add support for pinning and unpinning
messages get pinned in the same channel as the message was reacted to
This commit is contained in:
parent
96a4fe5751
commit
1e6289872d
24
bot.rb
24
bot.rb
@ -3,11 +3,19 @@ require 'discordrb'
|
|||||||
|
|
||||||
bot = Discordrb::Bot.new token: ENV['DISCORD_TOKEN']
|
bot = Discordrb::Bot.new token: ENV['DISCORD_TOKEN']
|
||||||
|
|
||||||
EMOJI = '🔖'
|
BOOKMARK_EMOJI = '🔖'
|
||||||
|
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 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
|
# extract data of the message's author
|
||||||
message_author = event.message.author
|
message_author = event.message.author
|
||||||
message_author_pfp = message_author.avatar_url 'png'
|
message_author_pfp = message_author.avatar_url 'png'
|
||||||
@ -28,7 +36,19 @@ bot.reaction_add do |event|
|
|||||||
embed << Discordrb::Webhooks::EmbedField.new(name: 'Message (trimmed)', value: trimmed_msg)
|
embed << Discordrb::Webhooks::EmbedField.new(name: 'Message (trimmed)', value: trimmed_msg)
|
||||||
embed.timestamp = event.message.timestamp
|
embed.timestamp = event.message.timestamp
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if(event.emoji.name == PIN_EMOJI)
|
||||||
|
Discordrb::API::Channel.pin_message(get_bot_token(), event.channel.id, event.message.id)
|
||||||
|
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.
|
||||||
end
|
end
|
||||||
|
|
||||||
|
bot.reaction_remove do |event|
|
||||||
|
next unless event.emoji.name == PIN_EMOJI
|
||||||
|
Discordrb::API::Channel.unpin_message(get_bot_token(), event.channel.id, event.message.id)
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
bot.run
|
bot.run
|
Loading…
Reference in New Issue
Block a user