aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamlon <stankiewiczgracjan2019@gmail.com>2025-08-12 21:11:23 +0200
committerSamlon <stankiewiczgracjan2019@gmail.com>2025-08-12 21:11:23 +0200
commita7c330ab81e3d10f8a0c1a1af51db5721cc3a747 (patch)
tree8dfceca2d2353da4eeb57b57604fb56e316968cd
parentsmall vclogs change (diff)
downloadsenator-sperma-a7c330ab81e3d10f8a0c1a1af51db5721cc3a747.tar.gz
senator-sperma-a7c330ab81e3d10f8a0c1a1af51db5721cc3a747.zip
rework ai and tts
Diffstat (limited to '')
-rw-r--r--cogs/ai.py27
-rw-r--r--cogs/tts.py7
2 files changed, 25 insertions, 9 deletions
diff --git a/cogs/ai.py b/cogs/ai.py
index 8c366a2..0a99c64 100644
--- a/cogs/ai.py
+++ b/cogs/ai.py
@@ -4,6 +4,8 @@ import discord
4import google.generativeai as genai 4import google.generativeai as genai
5from discord.ext import commands 5from discord.ext import commands
6import logging 6import logging
7import requests
8import json
7 9
8logger = logging.getLogger(__name__) 10logger = logging.getLogger(__name__)
9 11
@@ -22,13 +24,26 @@ class AI(commands.Cog):
22 text=discord.Option(str, "message", required=True) 24 text=discord.Option(str, "message", required=True)
23 ): 25 ):
24 await ctx.defer() 26 await ctx.defer()
25 genai.configure(api_key=os.getenv("GOOGLE_API_KEY")) 27
26 model = genai.GenerativeModel("gemini-1.5-flash") 28 response = requests.post(
27 response = model.generate_content( 29 url="https://openrouter.ai/api/v1/chat/completions",
28 "You are Senator Steaven Sperma Armstrong from Metal Gear Rising Vengeance. Respond in plain text, no ** or "". If the message is in Polish, respond in Polish. Respond in 100 words. Respond accordingly to this message: " + text, 30 headers={
31 "Authorization": f"Bearer {os.getenv('OPENROUTER_API_KEY')}",
32 "Content-Type": "application/json",
33 },
34 data=json.dumps({
35 "model": "cognitivecomputations/dolphin-mistral-24b-venice-edition:free",
36 "messages": [
37 {
38 "role": "user",
39 "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 ** or "". If the message is in Polish, respond in Polish. Respond in 100 words. Respond accordingly to this message: " + text
40 }
41 ],
42
43 })
29 ) 44 )
30 await ctx.respond(response.text) 45 await ctx.send_followup(response.json()["choices"][0]["message"]["content"])
31 logger.info(f"AI command executed successfully") 46
32 47
33 48
34def setup(bot): 49def setup(bot):
diff --git a/cogs/tts.py b/cogs/tts.py
index 8076a2d..07212ee 100644
--- a/cogs/tts.py
+++ b/cogs/tts.py
@@ -8,7 +8,6 @@ import logging
8 8
9logger = logging.getLogger(__name__) 9logger = logging.getLogger(__name__)
10 10
11
12class TTS(commands.Cog): 11class TTS(commands.Cog):
13 def __init__(self, bot): 12 def __init__(self, bot):
14 self.bot = bot 13 self.bot = bot
@@ -20,14 +19,17 @@ class TTS(commands.Cog):
20 ): 19 ):
21 tts = gTTS(text=text, lang='pl') 20 tts = gTTS(text=text, lang='pl')
22 tts.save('tts.mp3') 21 tts.save('tts.mp3')
22
23 if output == "file": 23 if output == "file":
24 await ctx.respond(file=discord.File('tts.mp3')) 24 await ctx.respond(file=discord.File('tts.mp3'))
25 logger.info("TTS file sent") 25 logger.info("TTS file sent")
26 os.remove('tts.mp3') 26 os.remove('tts.mp3')
27 elif output == "vc": 27 elif output == "vc":
28 # Defer the response to avoid "Bot did not respond" message
29 await ctx.defer()
30
28 # Check if the user is in a voice channel 31 # Check if the user is in a voice channel
29 if not (ctx.author.voice and ctx.author.voice.channel): 32 if not (ctx.author.voice and ctx.author.voice.channel):
30 await ctx.respond("Musisz być na kanale głosowym, aby odtworzyć TTS!", ephemeral=True)
31 logger.info("User is not in a voice channel") 33 logger.info("User is not in a voice channel")
32 os.remove('tts.mp3') 34 os.remove('tts.mp3')
33 return 35 return
@@ -52,6 +54,5 @@ class TTS(commands.Cog):
52 logger.info("Unknown playback method") 54 logger.info("Unknown playback method")
53 os.remove('tts.mp3') 55 os.remove('tts.mp3')
54 56
55
56def setup(bot): 57def setup(bot):
57 bot.add_cog(TTS(bot)) 58 bot.add_cog(TTS(bot))