Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions examples/extension.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from matrix import Extension, Context

extension = Extension("math")


@extension.group("math", description="Math Group")
async def math_group(ctx: Context):
pass


@math_group.command()
async def add(ctx: Context, a: int, b: int):
await ctx.reply(f"**{a} + {b} = {a + b}**")


@math_group.command()
async def subtract(ctx: Context, a: int, b: int):
await ctx.reply(f"{a} - {b} = {a - b}")


@math_group.command()
async def multiply(ctx: Context, a: int, b: int):
await ctx.reply(f"{a} x {b} = {a * b}")


@math_group.command()
async def divide(ctx: Context, a: int, b: int):
await ctx.reply(f"{a} ÷ {b} = {a / b}")


@divide.error(ZeroDivisionError)
async def divide_error(ctx: Context, error):
await ctx.reply(f"Divide error: {error}")


"""
from matrix import Bot
from math_extension import extension as math_extension

bot = Bot(config="config.yaml")


bot.load_extension(math_extension)
bot.start()
"""
2 changes: 2 additions & 0 deletions matrix/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from .help import HelpCommand
from .checks import cooldown
from .room import Room
from .extension import Extension

__all__ = [
"Bot",
Expand All @@ -26,4 +27,5 @@
"HelpCommand",
"cooldown",
"Room",
"Extension",
]
Loading