potomark-bot-rb/bot.rb

111 lines
3.5 KiB
Ruby
Raw Normal View History

2022-09-18 00:01:06 +00:00
require 'dotenv/load'
require 'discordrb'
bot = Discordrb::Bot.new token: ENV['DISCORD_TOKEN']
BOOKMARK_EMOJI = '🔖'
PIN_EMOJI = '📌'
2023-05-19 11:13:32 +00:00
ADMIN_PASTA = 'Thats not how it works, thats an abuse of power and if you keep doing that you will quickly find yourself no longer a moderator at some point.'
2023-05-19 11:21:09 +00:00
ADMIN_PASTER = 'tahts not how itwh orksm, thas and buse fo bpower and ify oyu keep y doing that oyu woubll qucikyl find you slefo no l ogner a nmoderarort at so meo poitn.'
2023-05-19 12:07:29 +00:00
YUM = 'completely consequences'
2023-05-19 12:25:07 +00:00
AULT = '# IN VR'
2023-05-19 11:13:32 +00:00
2022-09-18 00:01:54 +00:00
TRIM_MESSAGE_LENGTH = 500
2022-09-18 00:01:06 +00:00
2023-02-11 15:28:31 +00:00
$sentence = {}
2022-09-18 00:01:06 +00:00
bot.reaction_add do |event|
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'
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
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
2022-12-14 04:21:20 +00:00
if trimmed_msg.empty?
trimmed_msg = "<empty>"
end
original_msg_link = event.message.link
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)
2022-12-14 04:21:20 +00:00
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
2022-09-18 00:01:06 +00:00
end
2022-09-18 00:01:06 +00:00
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
2022-10-26 11:06:13 +00:00
pin_reactions = event.message.reactions.filter {|el| el.name == PIN_EMOJI}
event.message.unpin if pin_reactions.empty?
nil
end
2023-02-11 15:28:31 +00:00
bot.message(in: Integer(ENV['SENTENCE_CHANNEL'])) do |event|
if ['?', '!', '.', '...', '?!'].include? event.message.content
2023-02-11 15:28:31 +00:00
if $sentence.empty?
next
end
event << "Congratulations, your sentence is: #{$sentence.values.join(" ").gsub(/\s([^\w\s])/, '\1')}#{event.message.content}"
2023-02-11 15:28:31 +00:00
$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
2023-05-19 11:13:32 +00:00
bot.message(with_text: '!abuse') do |event|
event << ADMIN_PASTA
end
2023-05-19 11:21:09 +00:00
bot.message(with_text: '!abue') do |event|
event << ADMIN_PASTER
end
2023-05-19 12:07:29 +00:00
bot.message(with_text: '!yum') do |event|
event << YUM
end
2023-05-19 12:25:07 +00:00
bot.message(with_text: '!ault') do |event|
event << AULT
end
2023-05-23 20:45:39 +00:00
bot.message() do |event|
2023-05-23 20:47:28 +00:00
if event.message.content.include? 'shit'
2023-05-23 20:45:39 +00:00
event << AULT
end
end
bot.run