diff options
| author | salmonik <raisersoft@proton.me> | 2026-02-04 16:19:22 +0100 |
|---|---|---|
| committer | salmonik <raisersoft@proton.me> | 2026-02-04 16:19:22 +0100 |
| commit | 72abc43db8f732743c65d6f6a820369ab8665766 (patch) | |
| tree | 094fafdb0baf2e06a02045b1b2c0be88931a379a /cogs/math.py | |
| parent | refactor music (diff) | |
| download | senator-sperma-72abc43db8f732743c65d6f6a820369ab8665766.tar.gz senator-sperma-72abc43db8f732743c65d6f6a820369ab8665766.zip | |
more asynchronous work and other minor improvements
Diffstat (limited to '')
| -rw-r--r-- | cogs/math.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/cogs/math.py b/cogs/math.py index 4bd62a0..bf164b3 100644 --- a/cogs/math.py +++ b/cogs/math.py | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | # https://codeberg.org/salmonik/senator-sperma | 4 | # https://codeberg.org/salmonik/senator-sperma |
| 5 | 5 | ||
| 6 | import logging | 6 | import logging |
| 7 | import subprocess | 7 | import asyncio |
| 8 | 8 | ||
| 9 | from discord import ApplicationContext | 9 | from discord import ApplicationContext |
| 10 | from discord.ext import commands | 10 | from discord.ext import commands |
| @@ -22,8 +22,9 @@ class Math(commands.Cog): | |||
| 22 | ) | 22 | ) |
| 23 | async def math(self, ctx: ApplicationContext, equation: str): | 23 | async def math(self, ctx: ApplicationContext, equation: str): |
| 24 | try: | 24 | try: |
| 25 | math = subprocess.check_output(f"qalc -e '{equation}'", shell=True) | 25 | math = await asyncio.create_subprocess_exec(f"qalc -e '{equation}'") |
| 26 | await ctx.respond(f"{equation} = {math.decode('utf-8').strip()}") | 26 | result = await math.wait() |
| 27 | await ctx.respond(f"{equation} = {result.decode('utf-8').strip()}") | ||
| 27 | logger.info(f"Math command executed: {equation}") | 28 | logger.info(f"Math command executed: {equation}") |
| 28 | except Exception as e: | 29 | except Exception as e: |
| 29 | await ctx.respond(e, ephemeral=True) | 30 | await ctx.respond(e, ephemeral=True) |
