diff options
Diffstat (limited to 'main.py')
| -rw-r--r-- | main.py | 47 |
1 files changed, 34 insertions, 13 deletions
| @@ -13,6 +13,8 @@ import discord | |||
| 13 | from discord.ext import commands | 13 | from discord.ext import commands |
| 14 | from dotenv import load_dotenv | 14 | from dotenv import load_dotenv |
| 15 | 15 | ||
| 16 | from cogs.voice import get_voice_manager | ||
| 17 | |||
| 16 | # Configure logging | 18 | # Configure logging |
| 17 | logging.basicConfig( | 19 | logging.basicConfig( |
| 18 | level=logging.INFO, | 20 | level=logging.INFO, |
| @@ -27,7 +29,11 @@ logger = logging.getLogger(__name__) | |||
| 27 | loop = asyncio.new_event_loop() | 29 | loop = asyncio.new_event_loop() |
| 28 | asyncio.set_event_loop(loop) | 30 | asyncio.set_event_loop(loop) |
| 29 | 31 | ||
| 30 | bot = commands.Bot(intents=discord.Intents.all(), loop=loop) | 32 | intents = discord.Intents.default() |
| 33 | intents.voice_states = True | ||
| 34 | intents.guilds = True | ||
| 35 | intents.messages = True | ||
| 36 | bot = commands.Bot(intents=intents, loop=loop) | ||
| 31 | 37 | ||
| 32 | settings = "settings.json" | 38 | settings = "settings.json" |
| 33 | 39 | ||
| @@ -41,27 +47,40 @@ async def on_ready(): | |||
| 41 | print(f"One-time invite (expires in 1 s or after 1 use): {invite.url}") | 47 | print(f"One-time invite (expires in 1 s or after 1 use): {invite.url}") |
| 42 | 48 | ||
| 43 | await channel.send("ŁUKASZ SPERMA AKTYWACJA") | 49 | await channel.send("ŁUKASZ SPERMA AKTYWACJA") |
| 50 | |||
| 51 | # Create settings.json if it doesn't exist | ||
| 44 | if not os.path.exists(settings): | 52 | if not os.path.exists(settings): |
| 53 | default_settings = { | ||
| 54 | 'volume': 1.0, | ||
| 55 | 'file_paths': ['audio', 'music', 'sounds', 'videos', 'images'], | ||
| 56 | 'baseurl': 'http://localhost:8080' | ||
| 57 | } | ||
| 45 | async with aiofiles.open(settings, 'w') as f: | 58 | async with aiofiles.open(settings, 'w') as f: |
| 46 | json.dump({ | 59 | await f.write(json.dumps(default_settings, indent=2)) |
| 47 | 'volume': 1.0, | 60 | logger.info("settings.json created") |
| 48 | 'audio_paths': ['audio', 'music', 'sounds'] | 61 | |
| 49 | }, f) | 62 | # Validate and fix settings.json if it exists |
| 50 | if os.path.exists(settings): | 63 | if os.path.exists(settings): |
| 51 | try: | 64 | try: |
| 52 | async with aiofiles.open(settings) as f: | 65 | async with aiofiles.open(settings, 'r') as f: |
| 53 | content = await f.read() | 66 | content = await f.read() |
| 67 | if not content.strip(): | ||
| 68 | raise json.JSONDecodeError("Empty file", "", 0) | ||
| 54 | data = json.loads(content) | 69 | data = json.loads(content) |
| 55 | assert 'volume' in data and isinstance(data['volume'], float) | 70 | assert 'volume' in data and isinstance(data['volume'], float) |
| 56 | assert 'audio_paths' in data and isinstance(data['audio_paths'], list) | 71 | assert 'file_paths' in data and isinstance(data['file_paths'], list) |
| 72 | assert 'baseurl' in data and isinstance(data['baseurl'], str) | ||
| 57 | except (json.JSONDecodeError, AssertionError) as error: | 73 | except (json.JSONDecodeError, AssertionError) as error: |
| 58 | logger.error(f"Error loading settings.json: {error}") | 74 | logger.error(f"Error loading settings.json: {error}") |
| 75 | default_settings = { | ||
| 76 | 'volume': 1.0, | ||
| 77 | 'file_paths': ['audio', 'music', 'sounds', 'videos', 'images'], | ||
| 78 | 'baseurl': 'http://localhost:8080' | ||
| 79 | } | ||
| 59 | async with aiofiles.open(settings, 'w') as f: | 80 | async with aiofiles.open(settings, 'w') as f: |
| 60 | json.dump({ | 81 | await f.write(json.dumps(default_settings, indent=2)) |
| 61 | 'volume': 1.0, | 82 | logger.info("settings.json recreated") |
| 62 | 'audio_paths': ['audio', 'music', 'sounds'] | 83 | |
| 63 | }, f) | ||
| 64 | logger.info("settings.json created") | ||
| 65 | 84 | ||
| 66 | 85 | ||
| 67 | if __name__ == "__main__": | 86 | if __name__ == "__main__": |
| @@ -73,13 +92,14 @@ if __name__ == "__main__": | |||
| 73 | 'cogs.web', | 92 | 'cogs.web', |
| 74 | 'cogs.ai', | 93 | 'cogs.ai', |
| 75 | 'cogs.conversion', | 94 | 'cogs.conversion', |
| 76 | 'cogs.math', | 95 | 'cogs.math_commands', |
| 77 | 'cogs.downloader', | 96 | 'cogs.downloader', |
| 78 | 'cogs.say', | 97 | 'cogs.say', |
| 79 | 'cogs.jarvis', | 98 | 'cogs.jarvis', |
| 80 | 'cogs.music.play_commands', | 99 | 'cogs.music.play_commands', |
| 81 | 'cogs.music.stop', | 100 | 'cogs.music.stop', |
| 82 | 'cogs.music.join', | 101 | 'cogs.music.join', |
| 102 | 'cogs.search', | ||
| 83 | ] | 103 | ] |
| 84 | 104 | ||
| 85 | try: | 105 | try: |
| @@ -93,6 +113,7 @@ if __name__ == "__main__": | |||
| 93 | raise ValueError("No token provided. Please set the TOKEN environment variable.") | 113 | raise ValueError("No token provided. Please set the TOKEN environment variable.") |
| 94 | 114 | ||
| 95 | bot.run(token) | 115 | bot.run(token) |
| 116 | |||
| 96 | except Exception as e: | 117 | except Exception as e: |
| 97 | logger.error(f"Error starting the bot: {e}") | 118 | logger.error(f"Error starting the bot: {e}") |
| 98 | sys.exit(1) | 119 | sys.exit(1) |
