Compare commits
No commits in common. "main" and "bb5ca3fd09001cfad375d052fa9c3eee24b61038" have entirely different histories.
main
...
bb5ca3fd09
15
README.md
15
README.md
@ -1,25 +1,16 @@
|
||||
# potomark is a simple bookmarking and pinning discord bot.
|
||||
there's no configuration besides a `.env` file with two keys:
|
||||
|
||||
- the bot's token `DISCORD_TOKEN`,
|
||||
- channel id for a sentence game `SENTENCE_CHANNEL`. if you don't want to enable the sentence game, set the key to `-1`.
|
||||
# potomark is a simple bookmarking discord bot.
|
||||
there's no configuration besides a `.env` file that stores the bot's token.
|
||||
|
||||
## why?
|
||||
because we needed a tiny, self hostable bot to remember things of importance for our equally tiny discord server.
|
||||
|
||||
## what it do?
|
||||
- DMs a user a link to any message they react with 🔖 to (tip: you can change the `BOOKMARK_EMOJI` constant in `bot.rb` to any built-in emoji). this also sends part of the message for quick access,
|
||||
- lets users pin messages to the channel by reacting with 📌 on that message (change `PIN_EMOJI` to change the emoji). if there are no more of that emoji reactions on the message, it gets unpinned.
|
||||
- lets users make sentences one word (or more) at a time in `SENTENCE_CHANNEL`. to finish a sentence, send either of these as a message: `?`, `!`, `.`, `...`, `?!`
|
||||
DMs a user a link to any message they reacte with 🔖 to (tip: you can change the `EMOJI` constant in `bot.rb` to any built-in emoji). also sends part of the message for quick access. that's it.
|
||||
|
||||
## how?
|
||||
requires [ruby](https://www.ruby-lang.org/) >= 3.0 and [bundler](https://bundler.io) >= 2.3.19. the only two dependencies are `dotenv` and `discordrb`, as specified in the `Gemfile`.
|
||||
|
||||
quick setup:
|
||||
```bash
|
||||
$ git clone https://git.poto.cafe/yagich/potomark-bot-rb.git && cd potomark-bot-rb
|
||||
$ echo 'DISCORD_TOKEN=YOUR.DISCORD.TOKEN.HERE' > .env
|
||||
$ echo 'SENTENCE_CHANNEL=SENTENCE_GAME_CHANNEL_ID' >> .env
|
||||
$ bundle install
|
||||
$ ruby bot.rb
|
||||
```
|
||||
|
106
bot.rb
106
bot.rb
@ -3,102 +3,32 @@ require 'discordrb'
|
||||
|
||||
bot = Discordrb::Bot.new token: ENV['DISCORD_TOKEN']
|
||||
|
||||
BOOKMARK_EMOJI = '🔖'
|
||||
PIN_EMOJI = '📌'
|
||||
|
||||
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.'
|
||||
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.'
|
||||
YUM = 'completely consequences'
|
||||
AULT = '# IN VR'
|
||||
|
||||
EMOJI = '🔖'
|
||||
TRIM_MESSAGE_LENGTH = 500
|
||||
|
||||
$sentence = {}
|
||||
|
||||
bot.reaction_add do |event|
|
||||
next unless [BOOKMARK_EMOJI, PIN_EMOJI].include? event.emoji.name
|
||||
return nil 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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
original_msg_link = event.message.link
|
||||
|
||||
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 = event.user.pm
|
||||
|
||||
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
|
||||
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
|
||||
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(" ").gsub(/\s([^\w\s])/, '\1')}#{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.message(with_text: '!abuse') do |event|
|
||||
event << ADMIN_PASTA
|
||||
end
|
||||
|
||||
bot.message(with_text: '!abue') do |event|
|
||||
event << ADMIN_PASTER
|
||||
end
|
||||
|
||||
bot.message(with_text: '!yum') do |event|
|
||||
event << YUM
|
||||
end
|
||||
|
||||
bot.message(with_text: '!ault') do |event|
|
||||
event << AULT
|
||||
end
|
||||
|
||||
bot.run
|
||||
bot.run
|
Loading…
Reference in New Issue
Block a user