diff options
Diffstat (limited to 'cogs/math_commands.py')
| -rw-r--r-- | cogs/math_commands.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/cogs/math_commands.py b/cogs/math_commands.py new file mode 100644 index 0000000..bf164b3 --- /dev/null +++ b/cogs/math_commands.py | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | # This file is part of Senator Sperma | ||
| 2 | # Licensed under the GPL-3.0 License | ||
| 3 | # Copyright (C) 2026 Salmonik @ salmonik@tuta.io | ||
| 4 | # https://codeberg.org/salmonik/senator-sperma | ||
| 5 | |||
| 6 | import logging | ||
| 7 | import asyncio | ||
| 8 | |||
| 9 | from discord import ApplicationContext | ||
| 10 | from discord.ext import commands | ||
| 11 | |||
| 12 | logger = logging.getLogger(__name__) | ||
| 13 | |||
| 14 | |||
| 15 | class Math(commands.Cog): | ||
| 16 | def __init__(self, bot): | ||
| 17 | self.bot = bot | ||
| 18 | |||
| 19 | @commands.slash_command( | ||
| 20 | name="math", | ||
| 21 | description="wrug szyskih matfisuf" | ||
| 22 | ) | ||
| 23 | async def math(self, ctx: ApplicationContext, equation: str): | ||
| 24 | try: | ||
| 25 | math = await asyncio.create_subprocess_exec(f"qalc -e '{equation}'") | ||
| 26 | result = await math.wait() | ||
| 27 | await ctx.respond(f"{equation} = {result.decode('utf-8').strip()}") | ||
| 28 | logger.info(f"Math command executed: {equation}") | ||
| 29 | except Exception as e: | ||
| 30 | await ctx.respond(e, ephemeral=True) | ||
| 31 | logger.error(f"Error in math command: {e}", exc_info=True) | ||
| 32 | |||
| 33 | |||
| 34 | def setup(bot): | ||
| 35 | bot.add_cog(Math(bot)) | ||
