forked from yagich/potomark-bot-rb
Compare commits
10 Commits
96a4fe5751
...
e75ac68a57
Author | SHA1 | Date | |
---|---|---|---|
e75ac68a57 | |||
ba2f91d620 | |||
8829c57dd7 | |||
6a10c6beb7 | |||
c66178451a | |||
24e13036ce | |||
e7a309a700 | |||
89a36914db | |||
39443ef5ef | |||
1e6289872d |
85
bot.rb
85
bot.rb
@ -3,32 +3,81 @@ 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
|
||||||
|
|
||||||
|
$sentence = {}
|
||||||
|
|
||||||
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
|
||||||
# extract data of the message's author
|
|
||||||
message_author = event.message.author
|
|
||||||
message_author_pfp = message_author.avatar_url 'png'
|
|
||||||
message_author_nickname = message_author.display_name
|
|
||||||
message_author_distinct = message_author.distinct
|
|
||||||
|
|
||||||
message_author_fname = "#{message_author_nickname} (#{message_author_distinct})" # this is the 'author' field of the embed
|
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'
|
||||||
|
message_author_nickname = message_author.display_name
|
||||||
|
message_author_distinct = message_author.distinct
|
||||||
|
|
||||||
trimmed_msg = "#{event.message.content[0..TRIM_MESSAGE_LENGTH]}#{'...' if event.message.content.length > TRIM_MESSAGE_LENGTH}" # trim the string to TRIM_MESSAGE_LENGTH chars max to not make the embed too huge
|
message_author_fname = "#{message_author_nickname} (#{message_author_distinct})" # this is the 'author' field of the embed
|
||||||
original_msg_link = event.message.link
|
|
||||||
|
|
||||||
pm = event.user.pm
|
trimmed_msg = "#{event.message.content[0..TRIM_MESSAGE_LENGTH]}#{'...' if event.message.content.length > TRIM_MESSAGE_LENGTH}" # trim the string to TRIM_MESSAGE_LENGTH chars max to not make the embed too huge
|
||||||
|
if trimmed_msg.empty?
|
||||||
|
trimmed_msg = "<empty>"
|
||||||
|
end
|
||||||
|
original_msg_link = event.message.link
|
||||||
|
|
||||||
pm.send_embed 'Bookmark created!' do |embed|
|
pm = event.user.pm
|
||||||
embed.title = 'Go to message'
|
|
||||||
embed.url = original_msg_link
|
pm.send_embed 'Bookmark created!' do |embed|
|
||||||
embed.author = Discordrb::Webhooks::EmbedAuthor.new(icon_url: message_author_pfp, name: message_author_fname)
|
embed.title = 'Go to message'
|
||||||
embed << Discordrb::Webhooks::EmbedField.new(name: 'Message (trimmed)', value: trimmed_msg)
|
embed.url = original_msg_link
|
||||||
embed.timestamp = event.message.timestamp
|
embed.author = Discordrb::Webhooks::EmbedAuthor.new(icon_url: message_author_pfp, name: message_author_fname)
|
||||||
|
embed << Discordrb::Webhooks::EmbedField.new(name: 'Message (trimmed)', value: trimmed_msg)
|
||||||
|
if !event.message.attachments.empty?
|
||||||
|
event.message.attachments.each_index do |idx|
|
||||||
|
attachment = event.message.attachments[idx]
|
||||||
|
embed << Discordrb::Webhooks::EmbedField.new(name: "Attachment \##{idx + 1}", value: attachment.url)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
embed.timestamp = event.message.timestamp
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if(event.emoji.name == PIN_EMOJI)
|
||||||
|
event.message.pin unless event.message.reactions.include? PIN_EMOJI
|
||||||
|
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.run
|
bot.reaction_remove do |event|
|
||||||
|
next unless event.emoji.name == PIN_EMOJI
|
||||||
|
pin_reactions = event.message.reactions.filter {|el| el.name == PIN_EMOJI}
|
||||||
|
event.message.unpin if pin_reactions.empty?
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
|
bot.message(in: Integer(ENV['SENTENCE_CHANNEL'])) do |event|
|
||||||
|
if event.message.content == "."
|
||||||
|
if $sentence.empty?
|
||||||
|
next
|
||||||
|
end
|
||||||
|
event << "Congratulations, your sentence is: #{$sentence.values.join(" ")}."
|
||||||
|
$sentence.clear
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
|
$sentence[event.message.id] = event.message.content
|
||||||
|
end
|
||||||
|
|
||||||
|
bot.message_delete(in: Integer(ENV['SENTENCE_CHANNEL'])) do |event|
|
||||||
|
$sentence.delete(event.id)
|
||||||
|
end
|
||||||
|
|
||||||
|
bot.message_edit(in: Integer(ENV['SENTENCE_CHANNEL'])) do |event|
|
||||||
|
$sentence[event.message.id] = event.message.content
|
||||||
|
end
|
||||||
|
|
||||||
|
bot.run
|
||||||
|
Loading…
Reference in New Issue
Block a user