diff options
| author | Samlon <stankiewiczgracjan2019@gmail.com> | 2025-08-20 20:11:34 +0200 |
|---|---|---|
| committer | Samlon <stankiewiczgracjan2019@gmail.com> | 2025-08-20 20:11:34 +0200 |
| commit | 811e2cc7414eb78bb2bf964f986846f1f35e8748 (patch) | |
| tree | de77c68bdc63e1ca39d0577a183902eca7092e1c /cogs/math_cog.py | |
| parent | git being git (diff) | |
| download | senator-sperma-811e2cc7414eb78bb2bf964f986846f1f35e8748.tar.gz senator-sperma-811e2cc7414eb78bb2bf964f986846f1f35e8748.zip | |
improved downloader.py
Diffstat (limited to 'cogs/math_cog.py')
| -rw-r--r-- | cogs/math_cog.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/cogs/math_cog.py b/cogs/math_cog.py new file mode 100644 index 0000000..8a2644c --- /dev/null +++ b/cogs/math_cog.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)) | ||
