add support for pinning and unpinning #1

Merged
yagich merged 2 commits from mud/potomark-bot-rb:feature/pinning into main 2022-10-26 10:29:30 +00:00
Showing only changes of commit 39443ef5ef - Show all commits

8
bot.rb
View File

@ -8,10 +8,6 @@ PIN_EMOJI = '📌'
TRIM_MESSAGE_LENGTH = 500 TRIM_MESSAGE_LENGTH = 500
def get_bot_token
"Bot #{ENV['DISCORD_TOKEN']}"
end
bot.reaction_add do |event| bot.reaction_add do |event|
next unless [BOOKMARK_EMOJI, PIN_EMOJI].include? event.emoji.name next unless [BOOKMARK_EMOJI, PIN_EMOJI].include? event.emoji.name
@ -39,7 +35,7 @@ bot.reaction_add do |event|
end end
if(event.emoji.name == PIN_EMOJI) if(event.emoji.name == PIN_EMOJI)
Discordrb::API::Channel.pin_message(get_bot_token(), event.channel.id, event.message.id) event.message.pin
end end
nil # `event` is of type Respondable, so the return line of the block needs to be nil to prevent the bot sending something in the chhannel the reaction occured. nil # `event` is of type Respondable, so the return line of the block needs to be nil to prevent the bot sending something in the chhannel the reaction occured.
@ -47,7 +43,7 @@ end
bot.reaction_remove do |event| bot.reaction_remove do |event|
next unless event.emoji.name == PIN_EMOJI next unless event.emoji.name == PIN_EMOJI
Discordrb::API::Channel.unpin_message(get_bot_token(), event.channel.id, event.message.id) event.message.unpin
nil nil
end end