Skip to content

Commit fee3d76

Browse files
authored
Bot Extension (#31)
* WIP registry + refector of commands and new extension * fix registry name * Fix for custom prefix per commands (might need some optimization) * Fix bot tests * Added unload extension and fixed scheduler rigstration * Added on_load/load and on_unload/unload * Fix and added tests * Fix mypy issues * reformat * Add extension example
1 parent dd753b6 commit fee3d76

13 files changed

Lines changed: 1387 additions & 304 deletions

examples/extension.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from matrix import Extension, Context
2+
3+
extension = Extension("math")
4+
5+
6+
@extension.group("math", description="Math Group")
7+
async def math_group(ctx: Context):
8+
pass
9+
10+
11+
@math_group.command()
12+
async def add(ctx: Context, a: int, b: int):
13+
await ctx.reply(f"**{a} + {b} = {a + b}**")
14+
15+
16+
@math_group.command()
17+
async def subtract(ctx: Context, a: int, b: int):
18+
await ctx.reply(f"{a} - {b} = {a - b}")
19+
20+
21+
@math_group.command()
22+
async def multiply(ctx: Context, a: int, b: int):
23+
await ctx.reply(f"{a} x {b} = {a * b}")
24+
25+
26+
@math_group.command()
27+
async def divide(ctx: Context, a: int, b: int):
28+
await ctx.reply(f"{a} ÷ {b} = {a / b}")
29+
30+
31+
@divide.error(ZeroDivisionError)
32+
async def divide_error(ctx: Context, error):
33+
await ctx.reply(f"Divide error: {error}")
34+
35+
36+
"""
37+
from matrix import Bot
38+
from math_extension import extension as math_extension
39+
40+
bot = Bot(config="config.yaml")
41+
42+
43+
bot.load_extension(math_extension)
44+
bot.start()
45+
"""

matrix/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from .help import HelpCommand
1616
from .checks import cooldown
1717
from .room import Room
18+
from .extension import Extension
1819

1920
__all__ = [
2021
"Bot",
@@ -26,4 +27,5 @@
2627
"HelpCommand",
2728
"cooldown",
2829
"Room",
30+
"Extension",
2931
]

0 commit comments

Comments
 (0)