diff options
| author | salmonik <raisersoft@proton.me> | 2026-07-08 02:13:35 +0200 |
|---|---|---|
| committer | salmonik <raisersoft@proton.me> | 2026-07-08 02:13:35 +0200 |
| commit | cd8ed8bc5793985df2c1692072a932ceee517b95 (patch) | |
| tree | 42d18a4140259b5c68b4dd05b7fcb398f78b8d7f /cogs/ai.py | |
| parent | Merge pull request 'Voice related fixes, alongside simplifying assistant' (#5... (diff) | |
| download | senator-sperma-cd8ed8bc5793985df2c1692072a932ceee517b95.tar.gz senator-sperma-cd8ed8bc5793985df2c1692072a932ceee517b95.zip | |
OPEN THE RUST GATES
Signed-off-by: salmonik <raisersoft@proton.me>
Diffstat (limited to '')
| -rw-r--r-- | cogs/ai.py | 78 |
1 files changed, 0 insertions, 78 deletions
diff --git a/cogs/ai.py b/cogs/ai.py deleted file mode 100644 index ef2ba7c..0000000 --- a/cogs/ai.py +++ /dev/null | |||
| @@ -1,78 +0,0 @@ | |||
| 1 | # This file is part of Senator Sperma | ||
| 2 | # Licensed under the GPL-3.0 License | ||
| 3 | # Copyright (C) 2026 Salmonik @ salmonik@tuta.io | ||
| 4 | # https://codeberg.org/salmonik/senator-sperma | ||
| 5 | |||
| 6 | import os | ||
| 7 | import discord | ||
| 8 | from discord.ext import commands | ||
| 9 | import logging | ||
| 10 | import httpx | ||
| 11 | from gtts import gTTS | ||
| 12 | import io | ||
| 13 | |||
| 14 | logger = logging.getLogger(__name__) | ||
| 15 | |||
| 16 | class AI(commands.Cog): | ||
| 17 | def __init__(self, bot): | ||
| 18 | self.bot = bot | ||
| 19 | |||
| 20 | @commands.slash_command( | ||
| 21 | name="senator", | ||
| 22 | description="SEENATOR", | ||
| 23 | ) | ||
| 24 | async def senator( | ||
| 25 | self, | ||
| 26 | ctx: discord.ApplicationContext, | ||
| 27 | text: str = discord.Option(str, "message", required=True), | ||
| 28 | tts: str = discord.Option(bool, "face?", default=False) | ||
| 29 | ): | ||
| 30 | await ctx.defer() | ||
| 31 | |||
| 32 | |||
| 33 | url = "https://openrouter.ai/api/v1/chat/completions" | ||
| 34 | headers = { | ||
| 35 | "Authorization": f"Bearer {os.getenv('OPENROUTER_API_KEY')}", | ||
| 36 | "Content-Type": "application/json", | ||
| 37 | } | ||
| 38 | payload = { | ||
| 39 | "model": "cognitivecomputations/dolphin-mistral-24b-venice-edition:free", | ||
| 40 | "messages": [ | ||
| 41 | { | ||
| 42 | "role": "system", | ||
| 43 | "content": "You are Senator Steaven Sperma Armstrong from Metal Gear Rising Vengeance. \ | ||
| 44 | You are racist and you hate other minorities. Respond in plain text, no markdown tricks. \ | ||
| 45 | If the message is in Polish, respond in Polish. Respond in 100 words." | ||
| 46 | }, | ||
| 47 | { | ||
| 48 | "role": "user", | ||
| 49 | "content": text | ||
| 50 | } | ||
| 51 | ], | ||
| 52 | |||
| 53 | } | ||
| 54 | async with httpx.AsyncClient() as client: | ||
| 55 | response = await client.post(url=url, headers=headers, json=payload) | ||
| 56 | response_data = response.json() | ||
| 57 | logger.info(response_data) | ||
| 58 | if not response_data["choices"]: | ||
| 59 | await ctx.send_followup("bot siem zesroĊ") | ||
| 60 | else: | ||
| 61 | response_text = response_data["choices"][0]["message"]["content"] | ||
| 62 | if tts: | ||
| 63 | tts_obj = gTTS(text=response_text, lang='pl') | ||
| 64 | tts_buffer = io.BytesIO() | ||
| 65 | tts_obj.write_to_fp(tts_buffer) | ||
| 66 | tts_buffer.seek(0) | ||
| 67 | from cogs.voice import get_voice_manager | ||
| 68 | vm = get_voice_manager(self.bot) | ||
| 69 | channel = ctx.author.voice.channel | ||
| 70 | await vm.play_source(channel, discord.FFmpegPCMAudio(tts_buffer), interrupt=False) | ||
| 71 | |||
| 72 | else: | ||
| 73 | await ctx.send_followup(response_text) | ||
| 74 | |||
| 75 | |||
| 76 | |||
| 77 | def setup(bot): | ||
| 78 | bot.add_cog(AI(bot)) | ||
