From 063a34f20983b6acfe92d9b1b20cd441e96540c4 Mon Sep 17 00:00:00 2001 From: SamlonDev Date: Mon, 26 May 2025 17:55:12 +0200 Subject: volume control and fixes to math --- cogs/vc_logs.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'cogs/vc_logs.py') diff --git a/cogs/vc_logs.py b/cogs/vc_logs.py index 669be3b..e4a8454 100644 --- a/cogs/vc_logs.py +++ b/cogs/vc_logs.py @@ -1,8 +1,10 @@ + import discord from discord.ext import commands import datetime from gtts import gTTS import os +import json class vc_logs(commands.Cog): def __init__(self, bot): @@ -22,12 +24,37 @@ class vc_logs(commands.Cog): # Play the TTS audio if not voice_client.is_playing(): - audio_source = discord.FFmpegPCMAudio('temp_tts.mp3', options='-filter:a "volume=6"') + if os.path.exists('settings.json'): + with open('settings.json') as f: + data = json.load(f) + volume = data['volume'] + else: + with open('settings.json', 'w') as f: + json.dump({'volume': '5'}, f, indent=4) + + audio_source = discord.FFmpegPCMAudio('temp_tts.mp3', options=f'-filter:a "volume={volume}"') 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.slash_command( + name="log_volume" + ) + async def volume(self, ctx: discord.ApplicationContext, volume: int): + try: + if not os.path.exists('settings.json'): + with open('settings.json', 'w') as f: + json.dump({'volume': '5'}, f, indent=4) + with open('settings.json', 'w') as f: + json.dump({"volume": volume}, f, indent=4) + await ctx.send(f"Volume has been set to: {volume}") + except Exception as e: + await ctx.respond(e, ephemeral=True) + print(e) + + + @commands.Cog.listener() async def on_voice_state_update(self, member, before, after): log_channel = self.bot.get_channel(1213843195457183885) -- cgit v1.2.3