diff options
| -rw-r--r-- | cogs/vclogs.py | 14 | ||||
| -rw-r--r-- | main.py | 3 |
2 files changed, 9 insertions, 8 deletions
diff --git a/cogs/vclogs.py b/cogs/vclogs.py index bc317a4..0d8ca3b 100644 --- a/cogs/vclogs.py +++ b/cogs/vclogs.py | |||
| @@ -25,8 +25,8 @@ class VcLogs(commands.Cog): | |||
| 25 | 25 | ||
| 26 | @staticmethod | 26 | @staticmethod |
| 27 | def settings_check(): | 27 | def settings_check(): |
| 28 | if not os.path.exists(settings_file): | 28 | if not os.path.exists(VcLogs.settings_file): |
| 29 | with open(settings_file, 'w') as f: | 29 | with open(VcLogs.settings_file, 'w') as f: |
| 30 | json.dump({'volume': '5'}, f, indent=4) | 30 | json.dump({'volume': '5'}, f, indent=4) |
| 31 | logger.info("settings.json created") | 31 | logger.info("settings.json created") |
| 32 | 32 | ||
| @@ -67,8 +67,8 @@ class VcLogs(commands.Cog): | |||
| 67 | tts = gTTS(text=text, lang='pl') | 67 | tts = gTTS(text=text, lang='pl') |
| 68 | tts.save(tts_file) | 68 | tts.save(tts_file) |
| 69 | 69 | ||
| 70 | if os.path.exists(settings_file): | 70 | if os.path.exists(VcLogs.settings_file): |
| 71 | async with aiofiles.open(settings_file) as f: | 71 | async with aiofiles.open(VcLogs.settings_file) as f: |
| 72 | data = json.load(f) | 72 | data = json.load(f) |
| 73 | volume = data['volume'] | 73 | volume = data['volume'] |
| 74 | else: | 74 | else: |
| @@ -95,11 +95,11 @@ class VcLogs(commands.Cog): | |||
| 95 | ) | 95 | ) |
| 96 | async def volume(self, ctx: discord.ApplicationContext, volume: int): | 96 | async def volume(self, ctx: discord.ApplicationContext, volume: int): |
| 97 | try: | 97 | try: |
| 98 | if not os.path.exists(settings_file): | 98 | if not os.path.exists(VcLogs.settings_file): |
| 99 | async with aiofiles.open(settings_file, 'w') as f: | 99 | async with aiofiles.open(VcLogs.settings_file, 'w') as f: |
| 100 | json.dump({'volume': '5'}, f, indent=4) | 100 | json.dump({'volume': '5'}, f, indent=4) |
| 101 | logger.info("settings.json created") | 101 | logger.info("settings.json created") |
| 102 | async with aiofiles.open(settings_file, 'w') as f: | 102 | async with aiofiles.open(VcLogs.settings_file, 'w') as f: |
| 103 | json.dump({"volume": volume}, f, indent=4) | 103 | json.dump({"volume": volume}, f, indent=4) |
| 104 | await ctx.followup.send(f"Volume has been set to: {volume}") | 104 | await ctx.followup.send(f"Volume has been set to: {volume}") |
| 105 | logger.info(f"Volume changed to: {volume}") | 105 | logger.info(f"Volume changed to: {volume}") |
| @@ -46,7 +46,8 @@ async def on_ready(): | |||
| 46 | if os.path.exists(settings): | 46 | if os.path.exists(settings): |
| 47 | try: | 47 | try: |
| 48 | async with aiofiles.open(settings) as f: | 48 | async with aiofiles.open(settings) as f: |
| 49 | data = json.load(f) | 49 | content = await f.read() |
| 50 | data = json.loads(content) | ||
| 50 | assert 'volume' in data and isinstance(data['volume'], float) | 51 | assert 'volume' in data and isinstance(data['volume'], float) |
| 51 | assert 'audio_paths' in data and isinstance(data['audio_paths'], list) | 52 | assert 'audio_paths' in data and isinstance(data['audio_paths'], list) |
| 52 | except (json.JSONDecodeError, AssertionError) as error: | 53 | except (json.JSONDecodeError, AssertionError) as error: |
