diff options
| author | salmonik <raisersoft@proton.me> | 2026-02-04 16:19:22 +0100 |
|---|---|---|
| committer | salmonik <raisersoft@proton.me> | 2026-02-04 16:19:22 +0100 |
| commit | 72abc43db8f732743c65d6f6a820369ab8665766 (patch) | |
| tree | 094fafdb0baf2e06a02045b1b2c0be88931a379a /main.py | |
| parent | refactor music (diff) | |
| download | senator-sperma-72abc43db8f732743c65d6f6a820369ab8665766.tar.gz senator-sperma-72abc43db8f732743c65d6f6a820369ab8665766.zip | |
more asynchronous work and other minor improvements
Diffstat (limited to 'main.py')
| -rw-r--r-- | main.py | 15 |
1 files changed, 9 insertions, 6 deletions
| @@ -8,6 +8,7 @@ import os | |||
| 8 | import sys | 8 | import sys |
| 9 | import json | 9 | import json |
| 10 | import asyncio | 10 | import asyncio |
| 11 | import aiofiles | ||
| 11 | import discord | 12 | import discord |
| 12 | from discord.ext import commands | 13 | from discord.ext import commands |
| 13 | from dotenv import load_dotenv | 14 | from dotenv import load_dotenv |
| @@ -28,27 +29,29 @@ asyncio.set_event_loop(loop) | |||
| 28 | 29 | ||
| 29 | bot = commands.Bot(intents=discord.Intents.all(), loop=loop) | 30 | bot = commands.Bot(intents=discord.Intents.all(), loop=loop) |
| 30 | 31 | ||
| 32 | settings = "settings.json" | ||
| 33 | |||
| 31 | @bot.event | 34 | @bot.event |
| 32 | async def on_ready(): | 35 | async def on_ready(): |
| 33 | logger.info("ŁUKASZ SPERMA AKTYWACJA") | 36 | logger.info("ŁUKASZ SPERMA AKTYWACJA") |
| 34 | # send the message to channel ID | 37 | # send the message to channel ID |
| 35 | channel = bot.get_channel(1081667823799111804) | 38 | channel = bot.get_channel(1081667823799111804) |
| 36 | await channel.send("ŁUKASZ SPERMA AKTYWACJA") | 39 | await channel.send("ŁUKASZ SPERMA AKTYWACJA") |
| 37 | if not os.path.exists('settings.json'): | 40 | if not os.path.exists(settings): |
| 38 | with open('settings.json', 'w') as f: | 41 | async with aiofiles.open(settings, 'w') as f: |
| 39 | json.dump({ | 42 | json.dump({ |
| 40 | 'volume': 1.0, | 43 | 'volume': 1.0, |
| 41 | 'audio_paths': ['audio', 'music', 'sounds'] | 44 | 'audio_paths': ['audio', 'music', 'sounds'] |
| 42 | }, f) | 45 | }, f) |
| 43 | if os.path.exists('settings.json'): | 46 | if os.path.exists(settings): |
| 44 | try: | 47 | try: |
| 45 | with open('settings.json') as f: | 48 | async with aiofiles.open(settings) as f: |
| 46 | data = json.load(f) | 49 | data = json.load(f) |
| 47 | assert 'volume' in data and isinstance(data['volume'], float) | 50 | assert 'volume' in data and isinstance(data['volume'], float) |
| 48 | assert 'audio_paths' in data and isinstance(data['audio_paths'], list) | 51 | assert 'audio_paths' in data and isinstance(data['audio_paths'], list) |
| 49 | except (json.JSONDecodeError, AssertionError) as error: | 52 | except (json.JSONDecodeError, AssertionError) as error: |
| 50 | logger.error(f"Error loading settings.json: {error}") | 53 | logger.error(f"Error loading settings.json: {error}") |
| 51 | with open('settings.json', 'w') as f: | 54 | async with aiofiles.open(settings, 'w') as f: |
| 52 | json.dump({ | 55 | json.dump({ |
| 53 | 'volume': 1.0, | 56 | 'volume': 1.0, |
| 54 | 'audio_paths': ['audio', 'music', 'sounds'] | 57 | 'audio_paths': ['audio', 'music', 'sounds'] |
| @@ -69,7 +72,7 @@ if __name__ == "__main__": | |||
| 69 | 'cogs.downloader', | 72 | 'cogs.downloader', |
| 70 | 'cogs.say', | 73 | 'cogs.say', |
| 71 | 'cogs.jarvis', | 74 | 'cogs.jarvis', |
| 72 | 'cogs.music.play', | 75 | 'cogs.music.play_commands', |
| 73 | 'cogs.music.stop', | 76 | 'cogs.music.stop', |
| 74 | 'cogs.music.join', | 77 | 'cogs.music.join', |
| 75 | ] | 78 | ] |
