From fcc3635b9f24051ae07ed597632597e20372c889 Mon Sep 17 00:00:00 2001 From: SamlonDev Date: Tue, 20 May 2025 05:45:23 +0200 Subject: initial push --- cogs/vc_logs.py | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 cogs/vc_logs.py (limited to 'cogs/vc_logs.py') 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 @@ +import discord +from discord.ext import commands +import datetime +from gtts import gTTS +import os + +class vc_logs(commands.Cog): + def __init__(self, bot): + self.bot = bot + + async def play_tts(self, channel, text): + # Generate TTS audio + tts = gTTS(text=text, lang='pl') + tts.save('temp_tts.mp3') + + # Connect to voice channel if not already connected + voice_client = discord.utils.get(self.bot.voice_clients, guild=channel.guild) + if not voice_client or not voice_client.is_connected(): + voice_client = await channel.connect() + elif voice_client.channel != channel: + await voice_client.move_to(channel) + + # Play the TTS audio + if not voice_client.is_playing(): + audio_source = discord.FFmpegPCMAudio('temp_tts.mp3', options='-filter:a "volume=6"') + voice_client.play(audio_source) + while voice_client.is_playing(): + await discord.utils.sleep_until(datetime.datetime.now() + datetime.timedelta(seconds=1)) + os.remove('temp_tts.mp3') + + @commands.Cog.listener() + async def on_voice_state_update(self, member, before, after): + log_channel = self.bot.get_channel(1213843195457183885) + current_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") + tts_text = None + tts_channel = None + # Ignore if user is a bot + if member.bot: + return + if before.channel is None and after.channel is not None: + message = f"[{current_time}] {member.name} dołączył na {after.channel.name}" + tts_text = f"{member.display_name} sie zespawnił" + tts_channel = after.channel + await log_channel.send(message) + print(message) + elif before.channel is not None and after.channel is None: + message = f"[{current_time}] {member.name} rozłączył się z {before.channel.name}" + tts_text = f"{member.display_name} jest chujem" + tts_channel = before.channel + await log_channel.send(message) + print(message) + + if before.self_deaf != after.self_deaf: + if after.self_deaf: + message = f"[{current_time}] {member.name} ogłuchnął się na {after.channel.name}" + tts_text = f"{member.display_name} jest bity przez ojca" + else: + message = f"[{current_time}] {member.name} odgłuchął się na {after.channel.name}" + tts_text = f"{member.display_name} uciek od ojca" + tts_channel = after.channel + await log_channel.send(message) + print(message) + if tts_text and tts_channel: + await self.play_tts(tts_channel, tts_text) + return + + if before.self_mute != after.self_mute: + if after.self_mute: + message = f"[{current_time}] {member.name} wyciszył się na {after.channel.name}" + tts_text = f"{member.display_name} idzie robić jajecznice" + else: + message = f"[{current_time}] {member.name} odciszył się na {after.channel.name}" + tts_text = f"{member.display_name} zrobił jajecznice" + tts_channel = after.channel + await log_channel.send(message) + print(message) + + if tts_text and tts_channel: + await self.play_tts(tts_channel, tts_text) + + +def setup(bot): + bot.add_cog(vc_logs(bot)) \ No newline at end of file -- cgit v1.2.3