feat: discord bot (closes #55) #61
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This bot is currently built on Python and programmed to listen 24/7 to the commands inputted on a Discord server. It first listens to user commands on discord channels. For each command provoked by users, the bot will check the authentication status of the user by quering their API Keys in the bot database (I used Supabase as the bot's database for some reason). If the user is authenticated, the bot will send a POST request to the linkblocks app to input bookmarks under the "channel name"-tagged lists in linkblocks. Otherwise, the bot requires the user to generate a new API Key from linkblocks which will subsequently stored in the bot's database.
There are 3 commands available on this bot:
/linkblocks_auth
Used to inquire an API Key from Linkblocks. The bot will private message a URL that redirects the user to the linkblocks app. To generate one API Key, simply click the button and it will be redirected to the bot URL to be saved in the bot database (Just to know which user corresponds to which API token)
/import_to_linkblocks
Takes URLS as arguments (e.g:
/import_to_linkblocks https://google.com https://github.com
) and stores them as bookmarks under a list named after the channel name where the command was called./import_to_linkblocks_with_tag
Takes a list name as the first argument and URLS as the second and forth arguments (e.g:
/import_to_linkblocks_with_tag git https://github.com https://gitlab.com
) and stores them as bookmarks under a list with the tag nameTo run this PR, you need to first create a developer application on Discord (https://discord.com/developers/applications), then create a bot with
Message Content Intent
andServer Members Intent
enabled under thePrivileged Gateway Intents
, then copy the token and paste it under the.env
file. Next, you'll need Supabase URL and Supabase Key for the bot's database and the bot is ready to run!Essential code structure changed:
discord bot/
folder contains the code essential for the code to run, all you need is to run themain.py
fileuser_apis
table to store API token createdsrc/api.rs
added function of API communicationsrc/routes/api.rs
added endpoints for the bot to communicate withtemplates/api_key.html
added a simple web page to redirect the user to the bot's endpointOverall this PR is ready to run for tiny scale as the security is quite rough overall (but it's alr okay for the app scale itself). Any feedback toward this PR is highly welcomed and appreciated