Compare commits

..

14 Commits

Author SHA1 Message Date
83f6a5db1a Merge branch 'main' into feature/punctuation-sentence 2023-02-13 11:22:20 +00:00
ce02f1aeb5 use sentence ending event content when printing sentence 2023-02-13 12:21:20 +01:00
122447095b Merge pull request 'Feature | Add Support for More Punctuation Characters' (#3) from mud/potomark-bot-rb:feature/punctuation-sentence into main
Reviewed-on: yagich/potomark-bot-rb#3
2023-02-13 11:19:46 +00:00
0529dbac85 add support for more punctuation characters 2023-02-13 12:17:47 +01:00
e75ac68a57 patch misplaced period 2023-02-11 18:31:03 +03:00
ba2f91d620 add sentence game 2023-02-11 18:28:31 +03:00
8829c57dd7 fix attachment bookmarks 2022-12-14 07:21:20 +03:00
6a10c6beb7 properly resolve pin wars 2022-10-26 14:06:13 +03:00
c66178451a Merge pull request 'only perform pinning functions on first/last pin' (#2) from mud/potomark-bot-rb:feature/pinning into main
Reviewed-on: yagich/potomark-bot-rb#2
2022-10-26 10:55:49 +00:00
24e13036ce Merge branch 'main' into feature/pinning 2022-10-26 10:55:46 +00:00
e7a309a700 only perform pinning functions on first/last pin 2022-10-26 12:53:33 +02:00
89a36914db 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
2022-10-26 10:29:30 +00:00
39443ef5ef use message method instead of REST API 2022-10-26 12:27:34 +02:00
1e6289872d add support for pinning and unpinning
messages get pinned in the same channel as the message was reacted to
2022-10-26 11:41:33 +02:00

83
bot.rb
View File

@ -3,32 +3,81 @@ require 'discordrb'
bot = Discordrb::Bot.new token: ENV['DISCORD_TOKEN']
EMOJI = '🔖'
BOOKMARK_EMOJI = '🔖'
PIN_EMOJI = '📌'
TRIM_MESSAGE_LENGTH = 500
$sentence = {}
bot.reaction_add do |event|
next unless event.emoji.name == 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
next unless [BOOKMARK_EMOJI, PIN_EMOJI].include? event.emoji.name
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
original_msg_link = event.message.link
message_author_fname = "#{message_author_nickname} (#{message_author_distinct})" # this is the 'author' field of the embed
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|
embed.title = 'Go to message'
embed.url = original_msg_link
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)
embed.timestamp = event.message.timestamp
pm = event.user.pm
pm.send_embed 'Bookmark created!' do |embed|
embed.title = 'Go to message'
embed.url = original_msg_link
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
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.
end
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 ['?', '!', '.', '...'].include? event.message.content
if $sentence.empty?
next
end
event << "Congratulations, your sentence is: #{$sentence.values.join(" ")}${event.message.content}"
$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