Skip to content
 
 

Latest commit

 

History

392 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Demon Overlord

A discord bot custom built for the use of The InnerDemons discord community

The future of this bot

As some of you know discord.py, the library i use, has come to an end. Personally i completely understand it and i will not continue to develop this bot any further.

I entirely disagree with this stupid direction that discord is going in and will not rewrite this bot in another language. In other words: This bot will die once the library is fully deprecated by discord's actions I will continue hosting the bot as long as it will run and i will do the occasional bugfix, but nothing more. Honestly my motivation for this and patience with discord is at an end. It is open source for a reason, so go ahead and feel free to make your own fork.

Installation

THE BOT ONLY WORKS ON PYTHON 3.7+

The bot uses five environment variables

  • DISCORD_TESTBOT_TOKEN OR DISCORD_MAIN_TOKEN (depending on whether you're starting in testing mode or production.)
  • TENOR_TOKEN (an api token for tenor)
  • POSTGRES_USER (the postgres bot user)
  • POSTGRES_PASSWORD (the password for the postgres bot user)
  • POSTGRES_SERVER (the server address, e.g localhost:5000)
  • POSTGRES_PORT (the port on POSTGRES_SERVER )
  • POSTGRES_DB (The name of the bot database)

NOTE: You only need one of the bot keys.

To get a bot key:

  • if you are member of InnerDemons:
    1. Ask on #the-tech-basement on the Discord server to be added to the dev team
    2. Accept the invite
    3. Go to Applications and select the bot you want.
    4. Got to Bots copy the TOKEN next to the bot icon
  • else:
    1. go to the discord developer site
    2. create an application
    3. navigate to bot
    4. click Add Bot and confirm
    5. go to token and click copy
    6. this bot needs privileged gateway intents, so also scroll down and enable all of them
    7. to add the bot to a server just go to OAuth2 > scopes
    8. tick the bot scope, copy the URL and click copy
    9. paste the link into the browser and select the server where you wish to add the bot

Once you have the bot key, add the environment variable (this is how you do it in linux. For windows instructions, please consult the internet).

export <var_name>=<token_value>

Before you run it, please make sure you get the necessary dependencies

pip --user install -r requirements.txt

After that you will need a local postgreSQL database and set the envvars accordingly.

you can find more info in the postgres documentation.

Running The Bot

You can run the bot in two different modes.

FOR TESTING

Please only use testmao for testing any features.

python run.py --dev

FOR DEPLOYMENT

If you're trying to do this and you're reading this, you're doing something very wrong. Don't do it. This is a mode reserved exclusively for running it on the server and it uses a different token.

The directory structure

\-- DemonOverlord
   |-- config
   |   |-- cmd_info.json
   |   |-- config.json
   |   \-- special
   \-- core
       |-- modules
       \-- util

All source files concerning the bot are contained within the DemonOverlord directory. anything above that is unimportant and is mostly documentation or setup stuff. Anything below this will be relative to the DemonOverlord directory.

Config

This is the main directory for all the configuration files. These help keep the code cleaner and make simple text changes much easier.

The main config is config/config.json, which states all the necessary base configurations and definitions. It holds all the emoji, envvar names and prefixes the bot has in both production and testing mode.

config/cmd_info.json is all the help information for all commands. Any command the bot uses has to be added and documented here, so all its functions can easily be seen. Although it is mainly for the Help command, several other commands also use this file for extra functions.

Anything in the folder config/special is command specific info or configuration in the form of JSON files. These specify certain functionality or just text, so they are not hardcoded and keep the code cleaner.

Core

Anything in this folder is the core functionality and code of the bot. it also holds core/demonoverlord.py which is the main file that defined the DemonOverlord class. run.py in the root directory merely accesses this to create an instance of DemonOverlord.

The folder core/modules holds all the commands. Any command simply has an async function called handler, which returns an instance of one of the responses, which can be found in the core/util/responses.py or a custom response that inherits from one of them, as seen in core/modules/interactions.py, which takes an ImageResponse and sends that. The common ancestor to all of them is discord.Embed.

A simple command would be the Hello World command that is also implemented in core/modules/hello.py which simply greets the user that called the command. These commands are detected and imported automatically.

import discord
from DemonOverlord.core.util.responses import TextResponse

async def handler(command) -> discord.Embed:
    msg = {"name": "Response:", "value": f"Hello, {command.invoked_by.mention}"}
    res = TextResponse(
        "Command - Hello",
        color=0xEF1DD9,
        icon=command.bot.config.izzymojis["hello"] or "🌺",
        msg=msg,
    )
    return res

The last folder, core/util holds core utilities for the bot. In there is the Command class, which gets used in all commands, the responses, config handler and any tool the bot needs to fulfill its task. Any API definitions like Tenor or InspiroBot are also in here.

About

The main bot of the Inner Demons Discord server

Resources

Code of conduct

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages