Created
February 19, 2021 08:34
-
-
Save tomaszwro/c6574aa95c0c4009adcba92a8da2cec1 to your computer and use it in GitHub Desktop.
Discord-to-Slack bot
This file contains 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( | |
"https://hooks.slack.com/services/xxx/xxxx/xxxxx", | |
body: JSON.dump({ text: message }), | |
headers: { "Content-Type" => "application/json" } | |
) | |
end | |
bot = Discordrb::Bot.new(token: "xxxx.xxx.xxxx") | |
bot.voice_state_update do |event| | |
case | |
when event.channel.nil? | |
notify_slack "✂️ #{event.user.name} disconnected" | |
when event.old_channel.nil? | |
notify_slack "👋 #{event.user.name} connected to #{event.channel.name}" | |
when event.channel.name != event.old_channel.name | |
notify_slack "🔀 #{event.user.name} switched to #{event.channel.name}" | |
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