Compare commits

..

30 Commits

Author SHA1 Message Date
6a02eeb05f
add more up to date info to readme 2023-07-24 18:28:31 +03:00
61e8ff8b34
update install instructions 2023-07-24 18:19:30 +03:00
1d65101e33
remove whatever the fuck that was lol 2023-05-23 23:55:38 +03:00
133806aaa4
what am i doing with my life 3 2023-05-23 23:47:28 +03:00
679603e0a9
what am i doing with my life 2 2023-05-23 23:47:00 +03:00
f4522bddce
what am i doing with my life 2023-05-23 23:45:39 +03:00
e2240a75f1
add ault 2023-05-19 15:25:07 +03:00
ad9b7de2fc
add yum 2023-05-19 15:07:29 +03:00
4bfe4ef9d6
add admin paster 2023-05-19 14:21:09 +03:00
e5d0af7431
add admin abuse pasta 2023-05-19 14:13:32 +03:00
e56aac740b
remove space before all punctuation and add interrobang 2023-02-13 14:59:41 +03:00
738c4efa3b
remove space before comma 2023-02-13 14:36:25 +03:00
e26d385aed
patch incorrect string interp 2023-02-13 14:24:59 +03:00
5af24f2f02 Merge pull request 'Fix | Use Sentence Ending Event for Sentence' (#4) from mud/potomark-bot-rb:feature/punctuation-sentence into main
Reviewed-on: #4
2023-02-13 11:23:04 +00:00
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: #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: #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: #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
96a4fe5751
properly break from block 2022-09-18 03:08:59 +03:00
8c520afafa
add proper LICENSE file 2022-09-18 03:03:40 +03:00
3 changed files with 101 additions and 21 deletions

1
LICENSE Normal file
View File

@ -0,0 +1 @@
you may not use this code for any purpose.

View File

@ -1,16 +1,25 @@
# potomark is a simple bookmarking discord bot. # potomark is a simple bookmarking and pinning discord bot.
there's no configuration besides a `.env` file that stores the bot's token. 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`.
## why? ## why?
because we needed a tiny, self hostable bot to remember things of importance for our equally tiny discord server. because we needed a tiny, self hostable bot to remember things of importance for our equally tiny discord server.
## what it do? ## what it do?
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. - 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: `?`, `!`, `.`, `...`, `?!`
## how? ## 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`. 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 ```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 'DISCORD_TOKEN=YOUR.DISCORD.TOKEN.HERE' > .env
$ echo 'SENTENCE_CHANNEL=SENTENCE_GAME_CHANNEL_ID' >> .env
$ bundle install $ bundle install
$ ruby bot.rb $ ruby bot.rb
``` ```

104
bot.rb
View File

@ -3,32 +3,102 @@ require 'discordrb'
bot = Discordrb::Bot.new token: ENV['DISCORD_TOKEN'] bot = Discordrb::Bot.new token: ENV['DISCORD_TOKEN']
EMOJI = '🔖' 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'
TRIM_MESSAGE_LENGTH = 500 TRIM_MESSAGE_LENGTH = 500
$sentence = {}
bot.reaction_add do |event| bot.reaction_add do |event|
return nil 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.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