A command handler that complements Hikari. <3
Still in early development. See the TODO list.
Stable release
pip install yami
Development
pip install git+https://github.com/Jonxslays/Yami.git
import asyncio
import datetime
import functools
import os
import typing
import hikari
import yami
bot = yami.Bot(os.environ["TOKEN"], prefix="$")
# Can only be run in guilds.
@yami.is_in_guild()
@bot.command("add", "Adds 2 numbers", aliases=["sum"])
async def add_cmd(ctx: yami.MessageContext, num1: int, num2: int) -> None:
# Basic builtin python types are converted for you using their type
# hints (int, float, bool, complex, bytes). More types coming soon™.
await ctx.respond(f"The sum is {num1 + num2}")
# Can only be run by members with one of these roles.
@yami.has_any_role("Admin", "Fibonacci")
@bot.command("fibonacci", aliases=("fib",))
async def fibonacci(ctx: yami.MessageContext, num: int) -> None:
"""Calculates the num'th term in the fibonacci sequence."""
calc: typing.Callable[[int], int] = functools.lru_cache(
lambda n: n if n < 2 else calc(n - 1) + calc(n - 2)
)
# Though we cache the function call, let's simulate thinking.
async with ctx.trigger_typing():
await asyncio.sleep(0.75)
# Make a pretty embed.
await ctx.respond(
hikari.Embed(
title=f"Fibonacci calculator",
description=f"```{calc(num)}```",
color=hikari.Color(0x8AFF8A),
timestamp=datetime.datetime.now(tz=datetime.timezone.utc),
)
.set_footer(f"Term {num}")
.set_author(
name=(author := ctx.author).username,
icon=author.avatar_url or author.default_avatar_url,
)
)
if __name__ == "__main__":
bot.run()
✔️ Complete
- CI
- Testing (WIP)
- Fully typed
- Bot
- Message Commands
- Message Subcommands
- Message Context
- Modules
- Exceptions (WIP)
- Checks (WIP)
- Basic arg parsing (builtin types)
- Docs
- Events (Mostly)
❌ Incomplete
- Module listeners
- Hooks?
- Slash Commands
- Slash Context
- Converters (WIP)
- Utils (WIP)
- Full blown arg parsing (hikari types)
- QOL methods (WIP)
- Logging (WIP)
Yami is open to contributions. To get started check out the contributing guide.
Yami is licensed under the GPLV3 license.