Skip to main content

Building blocks and utility extensions for discord.py bots

Project description

Python versions License Status Issues Commit activity


Kasushi

Building blocks and utility extensions for discord.py bots


Kasushi is an extension of the discord.py library. It provides a number of useful features for bots, such as cache, IPC, tortoise models and more.

It is really easy to use, and requires a minimum amount of configuration.

  1. Download kasushi on the command line using pip:
pip install -U kasushi
  1. Configure the extensions:
import kasushi
# See below for settings you can pass to configure.
await kasushi.configure(bot, {}) 
  1. Load the extensions in your bot code before it runs:
await bot.load_extension('kasushi.cache')

You're done!

Modules and settings

Many modules are available in kasushi. You should load them in your bot, and pass settings to configure.

Depending on the module(s) you want to use, you can pass different settings to configure.

Cache

The cache module allows for connecting to a memcached server. It can be used to store cached data between reboots of the bot, like cooldowns and user data.

Usage

Once installed and loaded, the cache class is made available in bot.cache.

await bot.cache.set("coins", 0)
await bot.cache.set("coins", 10)
await bot.cache.get("coins")  # 10
await bot.cache.delete("coins")
await bot.cache.get("coins", default=5)  # 5

Configuration example

You can pass the following dictionary to configure:

{
    "cache": {
        "server_ip": "127.0.0.1",
        "server_port": 11211,
    }
}

IPC

IPC stands for Inter-Process Communication. It allows for sending messages between processes, or, in our case, different processes for the same bot.

The process hosting the first shard (shard 0) will be the "master process". It'll host the webserver allowing other processes to connect to it.

It'll also pass messages to the other bots if needed.

Usage

Once installed and loaded, the IPC class is made available in bot.ipc. All bots need to be able to access the first shard's IPC server.

Configuration example

{
    "ipc": {
        "shared_secret": "secret",  # This is used to authenticate with the IPC server.
        "server": {
            "host": "0.0.0.0",
            "port": 12321,
        },
        "client": {
            "server_url": "http://127.0.0.1:12321",
        },
        "handlers": [GuildInfoHandler]  # See above for handlers.
    },
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kasushi-0.1.2.tar.gz (13.2 kB view hashes)

Uploaded Source

Built Distribution

kasushi-0.1.2-py3-none-any.whl (10.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page