diff options
Diffstat (limited to 'cogs/vclogs.py')
| -rw-r--r-- | cogs/vclogs.py | 26 |
1 files changed, 8 insertions, 18 deletions
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 | |||
| 11 | import discord | 11 | import discord |
| 12 | from discord.ext import commands | 12 | from discord.ext import commands |
| 13 | from gtts import gTTS | 13 | from gtts import gTTS |
| 14 | import aiofiles | ||
| 15 | from cogs.voice import get_voice_manager | 14 | from cogs.voice import get_voice_manager |
| 15 | from cogs.utils.settings import get_volume, save_settings | ||
| 16 | 16 | ||
| 17 | logger = logging.getLogger(__name__) | 17 | logger = logging.getLogger(__name__) |
| 18 | 18 | ||
| @@ -51,8 +51,6 @@ class VcLogs(commands.Cog): | |||
| 51 | self._voice_manager = get_voice_manager(self.bot) | 51 | self._voice_manager = get_voice_manager(self.bot) |
| 52 | return self._voice_manager | 52 | return self._voice_manager |
| 53 | 53 | ||
| 54 | settings_file = 'settings.json' | ||
| 55 | |||
| 56 | @staticmethod | 54 | @staticmethod |
| 57 | async def handle_state_change(member, channel, state_type, is_enabled, log_channel): | 55 | async def handle_state_change(member, channel, state_type, is_enabled, log_channel): |
| 58 | """Helper method to handle voice state changes""" | 56 | """Helper method to handle voice state changes""" |
| @@ -81,13 +79,7 @@ class VcLogs(commands.Cog): | |||
| 81 | tts.save(tts_file) | 79 | tts.save(tts_file) |
| 82 | 80 | ||
| 83 | voice_client = await voice_mgr.get_voice_client(channel.guild) | 81 | voice_client = await voice_mgr.get_voice_client(channel.guild) |
| 84 | volume = 1.0 | 82 | volume = get_volume() |
| 85 | |||
| 86 | if os.path.exists(VcLogs.settings_file): | ||
| 87 | async with aiofiles.open(VcLogs.settings_file) as f: | ||
| 88 | content = await f.read() | ||
| 89 | data = json.loads(content) | ||
| 90 | volume = data.get('volume', 1.0) | ||
| 91 | 83 | ||
| 92 | if voice_client is None: | 84 | if voice_client is None: |
| 93 | voice_client = await voice_mgr.join_channel(channel) | 85 | voice_client = await voice_mgr.join_channel(channel) |
| @@ -107,14 +99,12 @@ class VcLogs(commands.Cog): | |||
| 107 | name="log_volume" | 99 | name="log_volume" |
| 108 | ) | 100 | ) |
| 109 | async def volume(self, ctx: discord.ApplicationContext, volume: int): | 101 | async def volume(self, ctx: discord.ApplicationContext, volume: int): |
| 110 | try: | 102 | from cogs.utils.settings import get_settings |
| 111 | async with aiofiles.open(VcLogs.settings_file, 'w') as f: | 103 | settings = get_settings() |
| 112 | json.dump({"volume": volume}, f, indent=4) | 104 | settings['volume'] = volume |
| 113 | await ctx.followup.send(f"Volume has been set to: {volume}") | 105 | await save_settings() |
| 114 | logger.info(f"Volume changed to: {volume}") | 106 | await ctx.followup.send(f"Volume has been set to: {volume}") |
| 115 | except Exception as e: | 107 | logger.info(f"Volume changed to: {volume}") |
| 116 | await ctx.respond(e, ephemeral=True) | ||
| 117 | logger.error(f"Error in volume command: {e}", exc_info=True) | ||
| 118 | 108 | ||
| 119 | @commands.Cog.listener() | 109 | @commands.Cog.listener() |
| 120 | async def on_voice_state_update(self, member, before, after): | 110 | async def on_voice_state_update(self, member, before, after): |
