diff --git a/.vscode/launch.json b/.vscode/launch.json index df1b6f5..a9f485f 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,6 +11,7 @@ "module": "lenaverse_bot.main", "justMyCode": true, "env": { + "LOG_LEVEL": "DEBUG", "CONFIG_PATH": "lenaverse-bot.toml", }, } diff --git a/lenaverse_bot/__init__.py b/lenaverse_bot/__init__.py index 47e8cfc..9254a05 100644 --- a/lenaverse_bot/__init__.py +++ b/lenaverse_bot/__init__.py @@ -1,3 +1,9 @@ +import logging +import os + import discord discord.utils.setup_logging() + +_logger = logging.getLogger(__name__) +_logger.setLevel(os.getenv("LOG_LEVEL", logging.WARN)) diff --git a/lenaverse_bot/core/bot.py b/lenaverse_bot/core/bot.py index 28fed11..1f8b8e0 100644 --- a/lenaverse_bot/core/bot.py +++ b/lenaverse_bot/core/bot.py @@ -24,8 +24,6 @@ class LenaverseBot(discord.Client): _logger.info("Commands synced") async def on_ready(self) -> None: - _logger.info(self.guilds) - if self.user is None: return diff --git a/lenaverse_bot/core/config.py b/lenaverse_bot/core/config.py index 5f2e4a5..ab4911b 100644 --- a/lenaverse_bot/core/config.py +++ b/lenaverse_bot/core/config.py @@ -1,3 +1,4 @@ +import logging import os import tomllib from typing import Self @@ -5,6 +6,8 @@ from typing import Self import discord from pydantic import BaseModel +_logger = logging.getLogger(__name__) + class PostTarget(BaseModel): server: str @@ -17,6 +20,7 @@ class PostTarget(BaseModel): """ guilds = [guild for guild in client.guilds if guild.name == self.server] + _logger.debug(f"Guilds: {[guild.name for guild in guilds]}") assert len(guilds) == 1 channels = [ @@ -25,11 +29,13 @@ class PostTarget(BaseModel): if isinstance(channel, discord.TextChannel | discord.ForumChannel) and channel.name == self.channel ] + _logger.debug(f"channels: {[channel.name for channel in channels]}") assert len(channels) == 1 threads = [ thread for thread in channels[0].threads if thread.name == self.thread ] + _logger.debug(f"threads: {[thread.name for thread in threads]}") assert len(threads) == 1 return threads[0] diff --git a/lenaverse_bot/core/post.py b/lenaverse_bot/core/post.py index e88dae4..313132f 100644 --- a/lenaverse_bot/core/post.py +++ b/lenaverse_bot/core/post.py @@ -73,7 +73,7 @@ class PostModal(ui.Modal, title="Post verfassen"): if view.action is Action.PUBLISH: # Post veröffentlichen _logger.info( - f"User {interaction.user.name}({interaction.user.id}) finished a /post" + f"User {interaction.user.name}({interaction.user.id}) published a /post" ) target = CONFIG.post.target.get(interaction.client) await target.send(post_content) @@ -97,7 +97,7 @@ async def post(interaction: discord.Interaction): if interaction.user.id in CONFIG.post.users: # Verfassen-Dialog anzeigen - _logger.info( + _logger.debug( f"User {interaction.user.name}({interaction.user.id}) started a /post" ) await interaction.response.send_modal(PostModal())