Skip to main content

A set of bot utilities for Discord.py

Project description

VoxelBotUtils

VoxelBotUtils is a package for extending the Discord.py library, intending to make creating bots just a lil bit faster by dealing with the overhead, like config files, help commands, and a bunch of more common utils like TimeValue.

Usage

This package is intended to be used via the commandline as a module. Running py -m voxelbotutils --create-config-file will create a default config file for you, and running py -m voxelbotutils . will run the current folder as a bot, using data in config/config.toml and loading the cogs from cogs/*.

What's in it

You may be thinking "why the heck would I use this?"

Database

I've included a database util! It's great! I like it! It uses PostgreSQL, using the data supplied in your config file. Used like so:

async with self.bot.database() as db:
    await db("INSERT INTO table_name (a, b, c) VALUES ($1, $2, $3)", 1, 2, 3)
    data = await db("SELECT * FROM table_name")
for row in data:  # data is used the same as a dictionary
    print(row['a'])

Redis

Redis; what a gem. I've only used it a couple of times so I'm not a big expert and I've not added a whole bunch to the util for it, but it's used in much the same way as the database in terms of SET/GET at least.

async with self.bot.redis() as re:
    await re.set("KEY", "Value")
    data = await re.get("KEY")
if data is not None:
    print(data)

Cooldowns

Rapptz's cooldown handling is not great if you want to do anything more complicated than "you all get cooldowns for X time". You want cooldowns in some channels and not others? You want cooldowns based on roles? That's possible with this.

@voxelbotutils.command()
@voxelbotutils.cooldown.cooldown(1, 60, commands.BucketType.user, cls=voxelbotutils.cooldown.RoleBasedCooldown())
async def commandname(self, ctx):
    ...

@voxelbotutils.command()
@voxelbotutils.cooldown.cooldown(1, 60, commands.BucketType.user, cls=voxelbotutils.cooldown.CooldownWithChannelExemptions(cooldown_in=["general"]))
async def commandname(self, ctx):
    ...

The current cooldowns I've got built into this right now aren't really wonderful but all of the systems are there for if you want to expand it.

Context Embeds

Setting up embeds always looked a bit messy to me, so I just added support for the with syntax so I could clean it up a lil. Apart from that they work pretty much identically to normal embeds.

with voxelbotutils.Embed() as embed:
    embed.set_author_to_user(user=self.bot.get_user(user_id))
    embed.description = "Lorem ipsum"
    embed.use_random_colour()

Docs

Documentation can be found here

Installing

The package is available via pypi - pip install voxelbotutils - but this package will always be further up-to-date with experimental or incomplete features should you wish to use that.

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

voxelbotutils-0.5.1.tar.gz (115.4 kB view hashes)

Uploaded Source

Built Distribution

voxelbotutils-0.5.1-py3-none-any.whl (151.6 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