forked from yagich/potomark-bot-rb
Merge pull request 'add support for pinning and unpinning' (#1) from mud/potomark-bot-rb:feature/pinning into main
Reviewed-on: yagich/potomark-bot-rb#1
This commit is contained in:
commit
89a36914db
20
bot.rb
20
bot.rb
@ -3,11 +3,15 @@ require 'discordrb'
|
||||
|
||||
bot = Discordrb::Bot.new token: ENV['DISCORD_TOKEN']
|
||||
|
||||
EMOJI = '🔖'
|
||||
BOOKMARK_EMOJI = '🔖'
|
||||
PIN_EMOJI = '📌'
|
||||
|
||||
TRIM_MESSAGE_LENGTH = 500
|
||||
|
||||
bot.reaction_add do |event|
|
||||
next unless event.emoji.name == EMOJI
|
||||
next unless [BOOKMARK_EMOJI, PIN_EMOJI].include? event.emoji.name
|
||||
|
||||
if(event.emoji.name == BOOKMARK_EMOJI)
|
||||
# extract data of the message's author
|
||||
message_author = event.message.author
|
||||
message_author_pfp = message_author.avatar_url 'png'
|
||||
@ -28,7 +32,19 @@ bot.reaction_add do |event|
|
||||
embed << Discordrb::Webhooks::EmbedField.new(name: 'Message (trimmed)', value: trimmed_msg)
|
||||
embed.timestamp = event.message.timestamp
|
||||
end
|
||||
end
|
||||
|
||||
if(event.emoji.name == PIN_EMOJI)
|
||||
event.message.pin
|
||||
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.
|
||||
end
|
||||
|
||||
bot.reaction_remove do |event|
|
||||
next unless event.emoji.name == PIN_EMOJI
|
||||
event.message.unpin
|
||||
nil
|
||||
end
|
||||
|
||||
bot.run
|
Loading…
Reference in New Issue
Block a user