aboutsummaryrefslogtreecommitdiffstats
path: root/cogs/vc_logs.py
diff options
context:
space:
mode:
authorSamlonDev <stankiewiczgracjan2019@gmail.com>2025-06-14 18:54:02 +0200
committerSamlonDev <stankiewiczgracjan2019@gmail.com>2025-06-14 18:54:02 +0200
commit791e75cb2beeca45a6edf52b65f7e299e03b5eaf (patch)
treecfee93211b7f8ac1c985325aaf8d9399b7a357ca /cogs/vc_logs.py
parenttemp downloads the files instead (diff)
downloadsenator-sperma-791e75cb2beeca45a6edf52b65f7e299e03b5eaf.tar.gz
senator-sperma-791e75cb2beeca45a6edf52b65f7e299e03b5eaf.zip
code-style issues
Diffstat (limited to 'cogs/vc_logs.py')
-rw-r--r--cogs/vc_logs.py110
1 files changed, 0 insertions, 110 deletions
diff --git a/cogs/vc_logs.py b/cogs/vc_logs.py
deleted file mode 100644
index e4a8454..0000000
--- a/cogs/vc_logs.py
+++ /dev/null
@@ -1,110 +0,0 @@
1
2import discord
3from discord.ext import commands
4import datetime
5from gtts import gTTS
6import os
7import json
8
9class vc_logs(commands.Cog):
10 def __init__(self, bot):
11 self.bot = bot
12
13 async def play_tts(self, channel, text):
14 # Generate TTS audio
15 tts = gTTS(text=text, lang='pl')
16 tts.save('temp_tts.mp3')
17
18 # Connect to voice channel if not already connected
19 voice_client = discord.utils.get(self.bot.voice_clients, guild=channel.guild)
20 if not voice_client or not voice_client.is_connected():
21 voice_client = await channel.connect()
22 elif voice_client.channel != channel:
23 await voice_client.move_to(channel)
24
25 # Play the TTS audio
26 if not voice_client.is_playing():
27 if os.path.exists('settings.json'):
28 with open('settings.json') as f:
29 data = json.load(f)
30 volume = data['volume']
31 else:
32 with open('settings.json', 'w') as f:
33 json.dump({'volume': '5'}, f, indent=4)
34
35 audio_source = discord.FFmpegPCMAudio('temp_tts.mp3', options=f'-filter:a "volume={volume}"')
36 voice_client.play(audio_source)
37 while voice_client.is_playing():
38 await discord.utils.sleep_until(datetime.datetime.now() + datetime.timedelta(seconds=1))
39 os.remove('temp_tts.mp3')
40
41 @commands.slash_command(
42 name="log_volume"
43 )
44 async def volume(self, ctx: discord.ApplicationContext, volume: int):
45 try:
46 if not os.path.exists('settings.json'):
47 with open('settings.json', 'w') as f:
48 json.dump({'volume': '5'}, f, indent=4)
49 with open('settings.json', 'w') as f:
50 json.dump({"volume": volume}, f, indent=4)
51 await ctx.send(f"Volume has been set to: {volume}")
52 except Exception as e:
53 await ctx.respond(e, ephemeral=True)
54 print(e)
55
56
57
58 @commands.Cog.listener()
59 async def on_voice_state_update(self, member, before, after):
60 log_channel = self.bot.get_channel(1213843195457183885)
61 current_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
62 tts_text = None
63 tts_channel = None
64 # Ignore if user is a bot
65 if member.bot:
66 return
67 if before.channel is None and after.channel is not None:
68 message = f"[{current_time}] {member.name} dołączył na {after.channel.name}"
69 tts_text = f"{member.display_name} sie zespawnił"
70 tts_channel = after.channel
71 await log_channel.send(message)
72 print(message)
73 elif before.channel is not None and after.channel is None:
74 message = f"[{current_time}] {member.name} rozłączył się z {before.channel.name}"
75 tts_text = f"{member.display_name} jest chujem"
76 tts_channel = before.channel
77 await log_channel.send(message)
78 print(message)
79
80 if before.self_deaf != after.self_deaf:
81 if after.self_deaf:
82 message = f"[{current_time}] {member.name} ogłuchnął się na {after.channel.name}"
83 tts_text = f"{member.display_name} jest bity przez ojca"
84 else:
85 message = f"[{current_time}] {member.name} odgłuchął się na {after.channel.name}"
86 tts_text = f"{member.display_name} uciek od ojca"
87 tts_channel = after.channel
88 await log_channel.send(message)
89 print(message)
90 if tts_text and tts_channel:
91 await self.play_tts(tts_channel, tts_text)
92 return
93
94 if before.self_mute != after.self_mute:
95 if after.self_mute:
96 message = f"[{current_time}] {member.name} wyciszył się na {after.channel.name}"
97 tts_text = f"{member.display_name} idzie robić jajecznice"
98 else:
99 message = f"[{current_time}] {member.name} odciszył się na {after.channel.name}"
100 tts_text = f"{member.display_name} zrobił jajecznice"
101 tts_channel = after.channel
102 await log_channel.send(message)
103 print(message)
104
105 if tts_text and tts_channel:
106 await self.play_tts(tts_channel, tts_text)
107
108
109def setup(bot):
110 bot.add_cog(vc_logs(bot)) \ No newline at end of file