From a548f460d0c404e7c876afdebb69f1c31aa06c0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lera=20Elvo=C3=A9?= Date: Sun, 18 Sep 2022 03:01:06 +0300 Subject: [PATCH] add functionality --- README.md | 23 +++++++++++++++++++++++ bot.rb | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 README.md create mode 100644 bot.rb diff --git a/README.md b/README.md new file mode 100644 index 0000000..8a1970d --- /dev/null +++ b/README.md @@ -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. +``` \ No newline at end of file diff --git a/bot.rb b/bot.rb new file mode 100644 index 0000000..8d48591 --- /dev/null +++ b/bot.rb @@ -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 \ No newline at end of file