1
0
Fork 0
mirror of https://code.lenaisten.de/Lenaisten/lenaverse-bot.git synced 2024-11-23 07:23:00 +00:00

logging improvements

This commit is contained in:
Jörn-Michael Miehe 2023-11-19 19:01:06 +01:00
parent 6f0c6d8f66
commit a7a1a3242e
5 changed files with 15 additions and 4 deletions

1
.vscode/launch.json vendored
View file

@ -11,6 +11,7 @@
"module": "lenaverse_bot.main",
"justMyCode": true,
"env": {
"LOG_LEVEL": "DEBUG",
"CONFIG_PATH": "lenaverse-bot.toml",
},
}

View file

@ -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))

View file

@ -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

View file

@ -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]

View file

@ -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())