Skip to content
libre-botsPublic

About

Shared functions and extensions every Libre Bot uses

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Libre Bots kit

The functions and lightbulb extensions every Libre Bot shares: configuration, the hub connection, translations, guild reporting, languages, privacy, command mentions and application emojis. It is a toolbox, not a framework. A bot calls it from its own start-up code, and nothing in it runs unless the bot names it.

pip install librebots-kit

Application emojis

A bot's own emojis are PNG or GIF files in one folder of its package, such as src/starboard/assets/emojis/, each named with 2 to 23 of a-z, 0-9 and _, such as star.png. ApplicationEmojis finds an emoji by that file stem, so the bot never names an id, which differs between the test bot and the real one.

The set-up step makes the application's emojis match the folder. It creates new and changed ones and then deletes every other application emoji, including any added by hand in the developer portal:

EMOJIS = Path(__file__).parent / "assets" / "emojis"

await ApplicationEmojis(rest).sync(await rest.fetch_application(), EMOJIS)

The running bot registers it for lightbulb's dependency injection and loads the emojis once at start, before the shards connect. Given the folder, load logs a warning naming each file the application has no emoji for:

emojis = ApplicationEmojis(bot.rest)
registry.register_value(ApplicationEmojis, emojis)


async def load_emojis(_: hikari.StartingEvent) -> None:
    await emojis.load(await bot.rest.fetch_application(), EMOJIS)


bot.subscribe(hikari.StartingEvent, load_emojis)

emojis.markup("star") gives the emoji for message text and emojis.emoji("star") the hikari.KnownCustomEmoji for buttons and select options. Without such an emoji they give "" and None, so a reply still goes out.

Development

You need mise.

mise install
  • make lint: ruff, pyright and actionlint
  • make test: the tests

Releases

A maintainer runs release in the Actions tab on main and chooses patch, minor or major, optionally as a release candidate. The run publishes the package to PyPI.

About

Shared functions and extensions every Libre Bot uses

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages