diff options
Diffstat (limited to 'cogs/math.py')
| -rw-r--r-- | cogs/math.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/cogs/math.py b/cogs/math.py new file mode 100644 index 0000000..8a2644c --- /dev/null +++ b/cogs/math.py | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | import logging | ||
| 2 | import subprocess | ||
| 3 | |||
| 4 | from discord import ApplicationContext | ||
| 5 | from discord.ext import commands | ||
| 6 | |||
| 7 | logger = logging.getLogger(__name__) | ||
| 8 | |||
| 9 | |||
| 10 | class Math(commands.Cog): | ||
| 11 | def __init__(self, bot): | ||
| 12 | self.bot = bot | ||
| 13 | |||
| 14 | @commands.slash_command( | ||
| 15 | name="math", | ||
| 16 | description="wrug szyskih matfisuf" | ||
| 17 | ) | ||
| 18 | async def math(self, ctx: ApplicationContext, equation: str): | ||
| 19 | try: | ||
| 20 | math = subprocess.check_output(f"qalc -e '{equation}'", shell=True) | ||
| 21 | await ctx.respond(f"{equation} = {math.decode('utf-8').strip()}") | ||
| 22 | logger.info(f"Math command executed: {equation}") | ||
| 23 | except Exception as e: | ||
| 24 | await ctx.respond(e, ephemeral=True) | ||
| 25 | logger.error(f"Error in math command: {e}", exc_info=True) | ||
| 26 | |||
| 27 | |||
| 28 | def setup(bot): | ||
| 29 | bot.add_cog(Math(bot)) | ||
