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 --- main.py | 39 +++------------------------------------ 1 file changed, 3 insertions(+), 36 deletions(-) (limited to 'main.py') diff --git a/main.py b/main.py index 25b7b33..67db667 100644 --- a/main.py +++ b/main.py @@ -6,14 +6,13 @@ import logging import os import sys -import json import asyncio -import aiofiles import discord from discord.ext import commands from dotenv import load_dotenv from cogs.voice import get_voice_manager +from cogs.utils import settings # Configure logging logging.basicConfig( @@ -32,49 +31,16 @@ asyncio.set_event_loop(loop) intents = discord.Intents.all() bot = commands.Bot(intents=intents, loop=loop) -settings = "settings.json" @bot.event async def on_ready(): logger.info("ŁUKASZ SPERMA AKTYWACJA") - # send the message to channel ID channel = bot.get_channel(1081667823799111804) await channel.send("ŁUKASZ SPERMA AKTYWACJA") - # Create settings.json if it doesn't exist - if not os.path.exists(settings): - default_settings = { - 'volume': 1.0, - 'file_paths': ['audio', 'music', 'sounds', 'videos', 'images'], - 'baseurl': 'http://localhost:8080' - } - async with aiofiles.open(settings, 'w') as f: - await f.write(json.dumps(default_settings, indent=2)) - logger.info("settings.json created") - - # Validate and fix settings.json if it exists - if os.path.exists(settings): - try: - async with aiofiles.open(settings, 'r') as f: - content = await f.read() - if not content.strip(): - raise json.JSONDecodeError("Empty file", "", 0) - data = json.loads(content) - assert 'volume' in data and isinstance(data['volume'], float) - assert 'file_paths' in data and isinstance(data['file_paths'], list) - assert 'baseurl' in data and isinstance(data['baseurl'], str) - except (json.JSONDecodeError, AssertionError) as error: - logger.error(f"Error loading settings.json: {error}") - default_settings = { - 'volume': 1.0, - 'file_paths': ['audio', 'music', 'sounds', 'videos', 'images'], - 'baseurl': 'http://localhost:8080' - } - async with aiofiles.open(settings, 'w') as f: - await f.write(json.dumps(default_settings, indent=2)) - logger.info("settings.json recreated") + await settings.load_settings() @@ -95,6 +61,7 @@ if __name__ == "__main__": 'cogs.music.stop', 'cogs.music.join', 'cogs.search', + 'cogs.trigger', ] try: -- cgit v1.2.3