Giter Club home page Giter Club logo

rubbergod's Introduction

Discord bot for the BUT FIT Discord server

About

This bot manages the verification process, karma and a bunch of other simple commands on our BUT FIT Discord server. It is written in Python with the help of Disnake and its DB runs on PostgreSQL with ORM.

Since the most of the features are custom-made, we wouldn't recommend using it for different servers.

Setup

Creating a Discord App

Before you proceed to the environment setup, you will need to create a Discord application to get the Discord API key. We will not provide you with the exact steps on how to do this as there already exists this awesome guide from the developers of Disnake, Discord API Python library.

  • When creating an invite URL in the Inviting Your Bot section, the bot and applications.commands scopes are required. We also strongly recommend choosing Administrator in the Bot permissions as it is hard to figure out which of these permissions you actually need for the development.

Important

You should set up a separate server just for the development purposes so it shouldn't be that much of a security risk anyway.

  • After you create the Discord application, one additional step is required. You will also need to enable SERVER MEMBERS INTENT in Bot tab:

image

Tip

You can do this by going to the Discord Developer Portal and selecting your newly created application. Then click on the Bot tab on the left and scroll down to the Privileged Gateway Intents section.

Installing and running the bot

Start by cloning the repo:

git clone https://github.com/Toaster192/rubbergod.git
cd rubbergod

Important

If you want to contribute to this project, refer to the contribution section first.

Configuration

cp config/config.template.toml config/config.toml

Now open the config.toml file in your editor. Insert the Discord API key you obtained earlier in the setup process:

1 [base]
2 command_prefix = ['?', '!']
3 default_prefix = '?'
4 ignored_prefixes = ['!']
5 key = '<Your Discord API key>'
...

Warning

Be careful. Bad things will happen if anyone else gets a possession of this key. Do not share it with anyone, ever!

On the next two lines, insert your Discord user and server ID so you get administrator rights over the bot:

6 admin_ids = [<Your Discord user ID>]
7 guild_id = <Your Server ID here>

Then, create the following 5 channels (or use one channel for all of them) on your server and paste their IDs to the config:

72 log_channel = <Channel ID>
73 bot_dev_channel = <Channel ID>
74 vote_room = <Channel ID>
75 bot_room = <Channel ID>
76 mod_room = <Channel ID>

(Optional) For some features you will also need to set other config variables, usually they are divided into categories based on cogs.

Permissions and variables

Caution

There are needed some additional steps for permissions and variables.

./init.sh

Docker setup (recommended)

Install Docker & Docker Compose V2 by going to their official documentation. Just select your OS and follow the steps.

  • Most installers should do that automatically, but just to be sure, enable docker service on startup: sudo systemctl enable --now docker.service.
  • To use Docker without sudo, you also need to be in docker group (eg. sudo usermod -aG docker $USER).
  • It's recommended to restart your system at this point (to get all the permissions and other stuff right).

a. Dev containers in VS Code (one click run) — preferred option

If you are using VS Code, you can simply run Rubbergod by using the Dev containers extension. Either by clicking on a notification or by clicking on arrows in bottom left corner (Open a Remote Window) and choosing Reopen in container.

b. Docker Compose CLI — if you don't use VS Code

This command should do the trick:

docker compose up

Docker will download all the necessary stuff and run the container. If you did everything correctly, bot will connect to the DB, load all the extensions and print Ready at the end. It will also send :peepowave: emoji to the #bot-room if you configured one. You're now all set!


Development

If you didn't run the container in detached mode, just press Ctrl+C to stop it.

Try to tweak some command a little bit and run the bot again, this time you can try to open it in detached mode so it won't block your terminal:

docker compose up --detach

Note

You can use shorter -d instead of --detach.

Important

If you changed some internal command logic, it should be applied instantly. If, however, your change involves Discord-side API changes — command name change, for example — it can take longer (few minutes to a few hours in extreme cases).

To stop the detached container, use this command:

docker compose down

Tips (optional)

Note

These things are not necessary for development but can help from time to time.

Enable commands sync debug

On startup the bot automatically syncs commands. Restarting the bot too frequently can lead to excessive synchronization attempts, causing the bot to time out from the Discord API. This timeout duration can vary widely, ranging anywhere from 10 minutes to up to X days. For debugging purposes it is recommended to set the sync_commands=False parameter. Be aware that the commands will not be updated on discord side (name, description, permissions, etc.), the functionality however will be updated.

Furthermore, if you want to enable command sync debugging info -- what exact update is being sent to the API and when --, you can also set the sync_commands_debug to True (info will be sent to stderr).

command_sync_flags=commands.CommandSyncFlags(sync_commands=True, sync_commands_debug=False),

Database-related tips can be found in database README.

List with all cogs, their commands and tasks can be found in cog README.


Local setup (not recommended)

Install the required Python modules (venv / --user flag recommended):

pip3 install -r requirements.txt

Run the bot (might want to use nohup or something):

python3 main.py

Required/recommended packages (apt)

git
python3.8
python3.8-dev
python3-pip
postgresql
postgresql-contrib
libpq-dev

Contribution

To participate in the development, you need to create a fork and send us your contributions through "Pull requests". You can read more in About forks and Creating a pull request guides directly from GitHub. It may look scary at the first moment, but don't worry, it's actually pretty simple. If you don't know where to start, we can help you on Discord (mentioned below).

pre-commit (useful for contributors)

We use pre-commit for lint check before each commit. Use it by running these commands:

pip install -r requirements-dev.txt
pre-commit install

Authors

Pull requests, issues or tips for new features are very much welcome!

Discord development channel

Got stuck with the above steps? Any questions?

You can discuss bot-related stuff in the #bot-development channel on the BUT FIT Discord server.

Other bots

GrillBot — our 2nd Discord bot almost entirely developed and maintained by @Misha12 aka Hobit.

Pumpkin.py — Highly modular Discord bot created by folks at BUT FEEC.

License

This project is licensed under the GNU GPL v.3 License.

rubbergod's People

Contributors

1ukastesar avatar adrijaned avatar denishromada avatar dependabot[bot] avatar dfajmon avatar flowernal avatar frnecas avatar georgjr2 avatar jogme avatar koscicz avatar kuba314 avatar lavirlifiliol avatar matesxs avatar michkot avatar misha12 avatar ondryaso avatar peterdragun avatar pre-commit-ci[bot] avatar radluy avatar safarradim avatar sinus-x avatar solumath avatar tedkozub avatar teflonek avatar thegreatfpmk avatar toaster192 avatar tomaskender avatar urumasi avatar viotaljiplk avatar wereii avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

rubbergod's Issues

Separate data access and Discord-facing methods

Classes in the repository package should only be used for fetching the data from the database, for the app design to be at least a bit right. This is most notable in the Karma class. Also, it doesn't really make sense for the Presence, Reaction, Rng, Roll, Verification and possible Utils classes to be in the repository package, as they don't interact with the database in any way.

Proposal: move the mentioned classes to a new package (name?) and refactor the Karma class by splitting its data access and user-facing functionality.

Delete deleted emotes from the database

Toaster pls mas v DB bordel (asi deleted emotes): bytearray(b'585113912165531661'), bytearray(b'589586181927206912'), bytearray(b'601860873232973824'), bytearray(b'602054332984066068'),

This is at the end of the !karma get output and could be used to delete all the emotes, just save the "errors" emojis into an array, not a string and do a delete for each of them

A "karma give" command for the admin

Add a command that only a user with ID matching the config.admin_id can use that will take a user(X) and a number(Y) as a parameter and will add / subtract Y karma from X

Discuss using some of the discord.ext.command features

These are the features I found could be of use in #38 and haven't been implemented yet:

Make a 'Cog' with features that are server specific

That way if anyone wants to use rubbergod on their server they can just not load the server related features like the new check roles and increment year commands
(or at least this way they will know they need to change the commands for them to work on their server)

Fix karma revote

  File "/home/xkinst01/.local/lib/python3.6/site-packages/discord/client.py", line 270, in _run_event
    await coro(*args, **kwargs)
  File "__main__.py", line 412, in on_message
    await karma.revote(message, config)
  File "/var/fitdiscord/rubbergod/repository/karma.py", line 192, in revote
    (emote.id, str(vote_value)))
  File "/home/xkinst01/.local/lib/python3.6/site-packages/mysql/connector/cursor.py", line 551, in execute
    self._handle_result(self._connection.cmd_query(stmt))
  File "/home/xkinst01/.local/lib/python3.6/site-packages/mysql/connector/connection.py", line 490, in cmd_query
    result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query))
  File "/home/xkinst01/.local/lib/python3.6/site-packages/mysql/connector/connection.py", line 395, in _handle_result
    raise errors.get_exception(packet)
mysql.connector.errors.IntegrityError: 1062 (23000): Duplicate entry '593337155301146631' for key 'emoji_id'```

Refactor reaction.py

The thing is horrible to read and the features should ideally handle how they react to reactions themselves.

Optimize the update_karma commands SQL

What I mean is the part where we fetch a number, increment / decrement it and then set the value in the database.

This could probably be done with a single UPDATE, not a SELECT, UPDATE.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.