8000 feat: discord bot (closes #55) by kimlimjustin · Pull Request #61 · raffomania/linkblocks · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: discord bot (closes #55) #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kimlimjustin
Copy link
Contributor

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:

  1. /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)
  2. /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.
  3. /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 name

To 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 and Server Members Intent enabled under the Privileged 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 the main.py file
  • Added user_apis table to store API token created
  • src/api.rs added function of API communication
  • src/routes/api.rs added endpoints for the bot to communicate with
  • templates/api_key.html added a simple web page to redirect the user to the bot's endpoint

Overall 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

@raffomania
Copy link
Owner

Hey! I'm a big fan of integrating linkblocks into other apps and would gladly accept a PR adding an API to do so. However, I don't want to maintain python code in this repository. The API you've added here seems to be well fit for other integrations as well, so if you'd move the python bot into a separate repository of yours, I'd be open to merging this :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0