forked from yagich/potomark-bot-rb
add functionality
This commit is contained in:
parent
a1b05103ed
commit
a548f460d0
23
README.md
Normal file
23
README.md
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# 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 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`.
|
||||||
|
```bash
|
||||||
|
$ echo 'DISCORD_TOKEN=YOUR.DISCORD.TOKEN.HERE' > .env
|
||||||
|
$ bundle install
|
||||||
|
$ ruby bot.rb
|
||||||
|
```
|
||||||
|
|
||||||
|
## license?
|
||||||
|
the full license text is as follows:
|
||||||
|
|
||||||
|
```
|
||||||
|
you may not use this code for any purpose.
|
||||||
|
```
|
33
bot.rb
Normal file
33
bot.rb
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
require 'dotenv/load'
|
||||||
|
require 'discordrb'
|
||||||
|
|
||||||
|
bot = Discordrb::Bot.new token: ENV['DISCORD_TOKEN']
|
||||||
|
|
||||||
|
EMOJI = '🔖'
|
||||||
|
|
||||||
|
bot.reaction_add do |event|
|
||||||
|
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
|
||||||
|
|
||||||
|
message_author_fname = "#{message_author_nickname} (#{message_author_distinct})" # this is the 'author' field of the embed
|
||||||
|
|
||||||
|
trimmed_msg = "#{event.message.content[0..500]}#{'...' if event.message.content.length > 500}" # trim the string to 500 chars max to not make the embed too huge
|
||||||
|
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)
|
||||||
|
embed.timestamp = event.message.timestamp
|
||||||
|
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.run
|
Loading…
Reference in New Issue
Block a user