From 106789319b1de06e9e8206c3a8d1dedab84496a1 Mon Sep 17 00:00:00 2001 From: salmonik Date: Mon, 23 Mar 2026 17:43:09 +0100 Subject: unify settings api into one file --- cogs/vclogs.py | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) (limited to 'cogs/vclogs.py') diff --git a/cogs/vclogs.py b/cogs/vclogs.py index f2efca7..0d80ae7 100644 --- a/cogs/vclogs.py +++ b/cogs/vclogs.py @@ -11,8 +11,8 @@ import asyncio import discord from discord.ext import commands from gtts import gTTS -import aiofiles from cogs.voice import get_voice_manager +from cogs.utils.settings import get_volume, save_settings logger = logging.getLogger(__name__) @@ -51,8 +51,6 @@ class VcLogs(commands.Cog): self._voice_manager = get_voice_manager(self.bot) return self._voice_manager - settings_file = 'settings.json' - @staticmethod async def handle_state_change(member, channel, state_type, is_enabled, log_channel): """Helper method to handle voice state changes""" @@ -81,13 +79,7 @@ class VcLogs(commands.Cog): tts.save(tts_file) voice_client = await voice_mgr.get_voice_client(channel.guild) - volume = 1.0 - - if os.path.exists(VcLogs.settings_file): - async with aiofiles.open(VcLogs.settings_file) as f: - content = await f.read() - data = json.loads(content) - volume = data.get('volume', 1.0) + volume = get_volume() if voice_client is None: voice_client = await voice_mgr.join_channel(channel) @@ -107,14 +99,12 @@ class VcLogs(commands.Cog): name="log_volume" ) async def volume(self, ctx: discord.ApplicationContext, volume: int): - try: - async with aiofiles.open(VcLogs.settings_file, 'w') as f: - json.dump({"volume": volume}, f, indent=4) - await ctx.followup.send(f"Volume has been set to: {volume}") - logger.info(f"Volume changed to: {volume}") - except Exception as e: - await ctx.respond(e, ephemeral=True) - logger.error(f"Error in volume command: {e}", exc_info=True) + from cogs.utils.settings import get_settings + settings = get_settings() + settings['volume'] = volume + await save_settings() + await ctx.followup.send(f"Volume has been set to: {volume}") + logger.info(f"Volume changed to: {volume}") @commands.Cog.listener() async def on_voice_state_update(self, member, before, after): -- cgit v1.2.3