aboutsummaryrefslogtreecommitdiffstats
path: root/cogs/ai.py
blob: dbdb02eea50fe87364d658e50010373b84be227a (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# 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 os
import discord
from discord.ext import commands
import logging
from gtts import gTTS
import io
from cogs.utils.llm import llm_completion

logger = logging.getLogger(__name__)

_DEFAULT_SENATOR_MODEL = "cognitivecomputations/dolphin-mistral-24b-venice-edition:free"

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

    @commands.slash_command(
        name="senator",
        description="SEENATOR",
    )
    async def senator(
            self,
            ctx: discord.ApplicationContext,
            text: str = discord.Option(str, "message", required=True),
            tts: str = discord.Option(bool, "face?", default=False)
    ):
        await ctx.defer()

        model = (
            os.getenv("LLM_MODEL")
            or os.getenv("OPENROUTER_MODEL")
            or _DEFAULT_SENATOR_MODEL
        )
        messages = [
            {
                "role": "system",
                "content": "You are Senator Steaven Sperma Armstrong from Metal Gear Rising Vengeance. \
                You are racist and you hate other minorities. Respond in plain text, no markdown tricks. \
                If the message is in Polish, respond in Polish. Respond in 100 words."
            },
            {
                "role": "user",
                "content": text
            }
        ]

        response_text = await llm_completion(messages, model=model)

        if response_text is None:
            await ctx.send_followup("bot siem zesroł")
            return

        if tts:
            tts_obj = gTTS(text=response_text, lang='pl')
            tts_buffer = io.BytesIO()
            tts_obj.write_to_fp(tts_buffer)
            tts_buffer.seek(0)
            from cogs.voice import get_voice_manager
            vm = get_voice_manager(self.bot)
            channel = ctx.author.voice.channel
            await vm.play_source(channel, discord.FFmpegPCMAudio(tts_buffer), interrupt=False)
        else:
            await ctx.send_followup(response_text)



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