aboutsummaryrefslogtreecommitdiffstats
path: root/cogs/vc_logs.py
diff options
context:
space:
mode:
Diffstat (limited to 'cogs/vc_logs.py')
-rw-r--r--cogs/vc_logs.py83
1 files changed, 83 insertions, 0 deletions
diff --git a/cogs/vc_logs.py b/cogs/vc_logs.py
new file mode 100644
index 0000000..669be3b
--- /dev/null
+++ b/cogs/vc_logs.py
@@ -0,0 +1,83 @@
1import discord
2from discord.ext import commands
3import datetime
4from gtts import gTTS
5import os
6
7class vc_logs(commands.Cog):
8 def __init__(self, bot):
9 self.bot = bot
10
11 async def play_tts(self, channel, text):
12 # Generate TTS audio
13 tts = gTTS(text=text, lang='pl')
14 tts.save('temp_tts.mp3')
15
16 # Connect to voice channel if not already connected
17 voice_client = discord.utils.get(self.bot.voice_clients, guild=channel.guild)
18 if not voice_client or not voice_client.is_connected():
19 voice_client = await channel.connect()
20 elif voice_client.channel != channel:
21 await voice_client.move_to(channel)
22
23 # Play the TTS audio
24 if not voice_client.is_playing():
25 audio_source = discord.FFmpegPCMAudio('temp_tts.mp3', options='-filter:a "volume=6"')
26 voice_client.play(audio_source)
27 while voice_client.is_playing():
28 await discord.utils.sleep_until(datetime.datetime.now() + datetime.timedelta(seconds=1))
29 os.remove('temp_tts.mp3')
30
31 @commands.Cog.listener()
32 async def on_voice_state_update(self, member, before, after):
33 log_channel = self.bot.get_channel(1213843195457183885)
34 current_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
35 tts_text = None
36 tts_channel = None
37 # Ignore if user is a bot
38 if member.bot:
39 return
40 if before.channel is None and after.channel is not None:
41 message = f"[{current_time}] {member.name} dołączył na {after.channel.name}"
42 tts_text = f"{member.display_name} sie zespawnił"
43 tts_channel = after.channel
44 await log_channel.send(message)
45 print(message)
46 elif before.channel is not None and after.channel is None:
47 message = f"[{current_time}] {member.name} rozłączył się z {before.channel.name}"
48 tts_text = f"{member.display_name} jest chujem"
49 tts_channel = before.channel
50 await log_channel.send(message)
51 print(message)
52
53 if before.self_deaf != after.self_deaf:
54 if after.self_deaf:
55 message = f"[{current_time}] {member.name} ogłuchnął się na {after.channel.name}"
56 tts_text = f"{member.display_name} jest bity przez ojca"
57 else:
58 message = f"[{current_time}] {member.name} odgłuchął się na {after.channel.name}"
59 tts_text = f"{member.display_name} uciek od ojca"
60 tts_channel = after.channel
61 await log_channel.send(message)
62 print(message)
63 if tts_text and tts_channel:
64 await self.play_tts(tts_channel, tts_text)
65 return
66
67 if before.self_mute != after.self_mute:
68 if after.self_mute:
69 message = f"[{current_time}] {member.name} wyciszył się na {after.channel.name}"
70 tts_text = f"{member.display_name} idzie robić jajecznice"
71 else:
72 message = f"[{current_time}] {member.name} odciszył się na {after.channel.name}"
73 tts_text = f"{member.display_name} zrobił jajecznice"
74 tts_channel = after.channel
75 await log_channel.send(message)
76 print(message)
77
78 if tts_text and tts_channel:
79 await self.play_tts(tts_channel, tts_text)
80
81
82def setup(bot):
83 bot.add_cog(vc_logs(bot)) \ No newline at end of file