diff options
| author | Samlon <stankiewiczgracjan2019@gmail.com> | 2025-08-13 14:59:22 +0200 |
|---|---|---|
| committer | Samlon <stankiewiczgracjan2019@gmail.com> | 2025-08-13 14:59:22 +0200 |
| commit | 8d0a52ab34563beab33be2dfb207da0e03a8fe32 (patch) | |
| tree | 6d670fe2985259c9c2a69ce80f1b8a0bd1d16d6c /cogs/vclogs.py | |
| parent | prevent discord from complaining (diff) | |
| download | senator-sperma-8d0a52ab34563beab33be2dfb207da0e03a8fe32.tar.gz senator-sperma-8d0a52ab34563beab33be2dfb207da0e03a8fe32.zip | |
prevent discord from complaining and bot does not leave vc after playing
Diffstat (limited to 'cogs/vclogs.py')
| -rw-r--r-- | cogs/vclogs.py | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/cogs/vclogs.py b/cogs/vclogs.py index 50c3fa7..9e74877 100644 --- a/cogs/vclogs.py +++ b/cogs/vclogs.py | |||
| @@ -2,7 +2,6 @@ import datetime | |||
| 2 | import json | 2 | import json |
| 3 | import logging | 3 | import logging |
| 4 | import os | 4 | import os |
| 5 | |||
| 6 | import discord | 5 | import discord |
| 7 | from discord.ext import commands | 6 | from discord.ext import commands |
| 8 | from gtts import gTTS | 7 | from gtts import gTTS |
| @@ -10,9 +9,21 @@ from gtts import gTTS | |||
| 10 | logger = logging.getLogger(__name__) | 9 | logger = logging.getLogger(__name__) |
| 11 | 10 | ||
| 12 | 11 | ||
| 12 | |||
| 13 | class VcLogs(commands.Cog): | 13 | class VcLogs(commands.Cog): |
| 14 | def __init__(self, bot): | 14 | def __init__(self, bot): |
| 15 | self.bot = bot | 15 | self.bot = bot |
| 16 | self.settings_check() | ||
| 17 | |||
| 18 | @staticmethod | ||
| 19 | def settings_check(): | ||
| 20 | if not os.path.exists('settings.json'): | ||
| 21 | with open('settings.json', 'w') as f: | ||
| 22 | json.dump({'volume': '5'}, f, indent=4) | ||
| 23 | logger.info("settings.json created") | ||
| 24 | with open('settings.json', 'r') as f: | ||
| 25 | settings = json.load(f) | ||
| 26 | volume = settings.get('volume', '5') | ||
| 16 | 27 | ||
| 17 | @staticmethod | 28 | @staticmethod |
| 18 | async def handle_state_change(member, channel, state_type, is_enabled, current_time, log_channel): | 29 | async def handle_state_change(member, channel, state_type, is_enabled, current_time, log_channel): |
| @@ -50,6 +61,13 @@ class VcLogs(commands.Cog): | |||
| 50 | tts = gTTS(text=text, lang='pl') | 61 | tts = gTTS(text=text, lang='pl') |
| 51 | tts.save('temp_tts.mp3') | 62 | tts.save('temp_tts.mp3') |
| 52 | 63 | ||
| 64 | if os.path.exists('settings.json'): | ||
| 65 | with open('settings.json') as f: | ||
| 66 | data = json.load(f) | ||
| 67 | volume = data['volume'] | ||
| 68 | else: | ||
| 69 | logger.error("settings.json not found") | ||
| 70 | |||
| 53 | # Connect to the voice channel if not already connected | 71 | # Connect to the voice channel if not already connected |
| 54 | voice_client = discord.utils.get(self.bot.voice_clients, guild=channel.guild) | 72 | voice_client = discord.utils.get(self.bot.voice_clients, guild=channel.guild) |
| 55 | if not voice_client or not voice_client.is_connected(): | 73 | if not voice_client or not voice_client.is_connected(): |
| @@ -59,15 +77,6 @@ class VcLogs(commands.Cog): | |||
| 59 | 77 | ||
| 60 | # Play the TTS audio | 78 | # Play the TTS audio |
| 61 | if not voice_client.is_playing(): | 79 | if not voice_client.is_playing(): |
| 62 | if os.path.exists('settings.json'): | ||
| 63 | with open('settings.json') as f: | ||
| 64 | data = json.load(f) | ||
| 65 | volume = data['volume'] | ||
| 66 | else: | ||
| 67 | with open('settings.json', 'w') as f: | ||
| 68 | json.dump({'volume': '5'}, f, indent=4) | ||
| 69 | logger.info("settings.json created") | ||
| 70 | |||
| 71 | audio_source = discord.FFmpegPCMAudio('temp_tts.mp3', options=f'-filter:a "volume={volume}"') | 80 | audio_source = discord.FFmpegPCMAudio('temp_tts.mp3', options=f'-filter:a "volume={volume}"') |
| 72 | voice_client.play(audio_source) | 81 | voice_client.play(audio_source) |
| 73 | while voice_client.is_playing(): | 82 | while voice_client.is_playing(): |
