-
-
Save Plutor/24bf5496025c50ee533fd3f0c538355a to your computer and use it in GitHub Desktop.
Discord-to-Slack bot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "discordrb" | |
require "httparty" | |
def notify_slack(message) | |
HTTParty.post( | |
# people_who_play_games | |
"https://hooks.slack.com/services/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", | |
body: JSON.dump({ | |
text: message, | |
username: "Discord announcement", | |
icon_emoji: ":mega:", | |
}), | |
headers: { "Content-Type" => "application/json" } | |
) | |
end | |
bot = Discordrb::Bot.new(token: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") | |
users = Hash.new | |
bot.voice_state_update do |event| | |
if event.channel.nil? | |
if !users.has_key?(event.user.name) | |
return | |
end | |
users.delete(event.user.name) | |
if users.length() == 0 | |
notify_slack "No one is chatting on Discord" | |
end | |
else | |
if users.has_key?(event.user.name) | |
return | |
end | |
if users.length() == 0 | |
notify_slack "Someone is chatting on <https://discord.gg/xxxxxxxxxxxxxxxxxxxxxxx|the Discord>" | |
end | |
users[event.user.name] = 1 | |
end | |
end | |
at_exit { bot.stop } | |
bot.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment