aboutsummaryrefslogtreecommitdiffstats
path: root/cogs/math.py
blob: bf164b38cdbb52309e2594a1c070f427f4355494 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# This file is part of Senator Sperma
# Licensed under the GPL-3.0 License
# Copyright (C) 2026 Salmonik @ salmonik@tuta.io
# https://codeberg.org/salmonik/senator-sperma

import logging
import asyncio

from discord import ApplicationContext
from discord.ext import commands

logger = logging.getLogger(__name__)


class Math(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @commands.slash_command(
        name="math",
        description="wrug szyskih matfisuf"
    )
    async def math(self, ctx: ApplicationContext, equation: str):
        try:
            math = await asyncio.create_subprocess_exec(f"qalc -e '{equation}'")
            result = await math.wait()
            await ctx.respond(f"{equation} = {result.decode('utf-8').strip()}")
            logger.info(f"Math command executed: {equation}")
        except Exception as e:
            await ctx.respond(e, ephemeral=True)
            logger.error(f"Error in math command: {e}", exc_info=True)


def setup(bot):
    bot.add_cog(Math(bot))