diff options
Diffstat (limited to 'main.py')
| -rw-r--r-- | main.py | 39 |
1 files changed, 3 insertions, 36 deletions
| @@ -6,14 +6,13 @@ | |||
| 6 | import logging | 6 | import logging |
| 7 | import os | 7 | import os |
| 8 | import sys | 8 | import sys |
| 9 | import json | ||
| 10 | import asyncio | 9 | import asyncio |
| 11 | import aiofiles | ||
| 12 | import discord | 10 | import discord |
| 13 | from discord.ext import commands | 11 | from discord.ext import commands |
| 14 | from dotenv import load_dotenv | 12 | from dotenv import load_dotenv |
| 15 | 13 | ||
| 16 | from cogs.voice import get_voice_manager | 14 | from cogs.voice import get_voice_manager |
| 15 | from cogs.utils import settings | ||
| 17 | 16 | ||
| 18 | # Configure logging | 17 | # Configure logging |
| 19 | logging.basicConfig( | 18 | logging.basicConfig( |
| @@ -32,49 +31,16 @@ asyncio.set_event_loop(loop) | |||
| 32 | intents = discord.Intents.all() | 31 | intents = discord.Intents.all() |
| 33 | bot = commands.Bot(intents=intents, loop=loop) | 32 | bot = commands.Bot(intents=intents, loop=loop) |
| 34 | 33 | ||
| 35 | settings = "settings.json" | ||
| 36 | 34 | ||
| 37 | @bot.event | 35 | @bot.event |
| 38 | async def on_ready(): | 36 | async def on_ready(): |
| 39 | logger.info("ŁUKASZ SPERMA AKTYWACJA") | 37 | logger.info("ŁUKASZ SPERMA AKTYWACJA") |
| 40 | 38 | ||
| 41 | # send the message to channel ID | ||
| 42 | channel = bot.get_channel(1081667823799111804) | 39 | channel = bot.get_channel(1081667823799111804) |
| 43 | 40 | ||
| 44 | await channel.send("ŁUKASZ SPERMA AKTYWACJA") | 41 | await channel.send("ŁUKASZ SPERMA AKTYWACJA") |
| 45 | 42 | ||
| 46 | # Create settings.json if it doesn't exist | 43 | await settings.load_settings() |
| 47 | if not os.path.exists(settings): | ||
| 48 | default_settings = { | ||
| 49 | 'volume': 1.0, | ||
| 50 | 'file_paths': ['audio', 'music', 'sounds', 'videos', 'images'], | ||
| 51 | 'baseurl': 'http://localhost:8080' | ||
| 52 | } | ||
| 53 | async with aiofiles.open(settings, 'w') as f: | ||
| 54 | await f.write(json.dumps(default_settings, indent=2)) | ||
| 55 | logger.info("settings.json created") | ||
| 56 | |||
| 57 | # Validate and fix settings.json if it exists | ||
| 58 | if os.path.exists(settings): | ||
| 59 | try: | ||
| 60 | async with aiofiles.open(settings, 'r') as f: | ||
| 61 | content = await f.read() | ||
| 62 | if not content.strip(): | ||
| 63 | raise json.JSONDecodeError("Empty file", "", 0) | ||
| 64 | data = json.loads(content) | ||
| 65 | assert 'volume' in data and isinstance(data['volume'], float) | ||
| 66 | assert 'file_paths' in data and isinstance(data['file_paths'], list) | ||
| 67 | assert 'baseurl' in data and isinstance(data['baseurl'], str) | ||
| 68 | except (json.JSONDecodeError, AssertionError) as error: | ||
| 69 | logger.error(f"Error loading settings.json: {error}") | ||
| 70 | default_settings = { | ||
| 71 | 'volume': 1.0, | ||
| 72 | 'file_paths': ['audio', 'music', 'sounds', 'videos', 'images'], | ||
| 73 | 'baseurl': 'http://localhost:8080' | ||
| 74 | } | ||
| 75 | async with aiofiles.open(settings, 'w') as f: | ||
| 76 | await f.write(json.dumps(default_settings, indent=2)) | ||
| 77 | logger.info("settings.json recreated") | ||
| 78 | 44 | ||
| 79 | 45 | ||
| 80 | 46 | ||
| @@ -95,6 +61,7 @@ if __name__ == "__main__": | |||
| 95 | 'cogs.music.stop', | 61 | 'cogs.music.stop', |
| 96 | 'cogs.music.join', | 62 | 'cogs.music.join', |
| 97 | 'cogs.search', | 63 | 'cogs.search', |
| 64 | 'cogs.trigger', | ||
| 98 | ] | 65 | ] |
| 99 | 66 | ||
| 100 | try: | 67 | try: |
