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:
parent
6f0c6d8f66
commit
a7a1a3242e
5 changed files with 15 additions and 4 deletions
1
.vscode/launch.json
vendored
1
.vscode/launch.json
vendored
|
@ -11,6 +11,7 @@
|
||||||
"module": "lenaverse_bot.main",
|
"module": "lenaverse_bot.main",
|
||||||
"justMyCode": true,
|
"justMyCode": true,
|
||||||
"env": {
|
"env": {
|
||||||
|
"LOG_LEVEL": "DEBUG",
|
||||||
"CONFIG_PATH": "lenaverse-bot.toml",
|
"CONFIG_PATH": "lenaverse-bot.toml",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,9 @@
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
|
|
||||||
discord.utils.setup_logging()
|
discord.utils.setup_logging()
|
||||||
|
|
||||||
|
_logger = logging.getLogger(__name__)
|
||||||
|
_logger.setLevel(os.getenv("LOG_LEVEL", logging.WARN))
|
||||||
|
|
|
@ -24,8 +24,6 @@ class LenaverseBot(discord.Client):
|
||||||
_logger.info("Commands synced")
|
_logger.info("Commands synced")
|
||||||
|
|
||||||
async def on_ready(self) -> None:
|
async def on_ready(self) -> None:
|
||||||
_logger.info(self.guilds)
|
|
||||||
|
|
||||||
if self.user is None:
|
if self.user is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
import tomllib
|
import tomllib
|
||||||
from typing import Self
|
from typing import Self
|
||||||
|
@ -5,6 +6,8 @@ from typing import Self
|
||||||
import discord
|
import discord
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class PostTarget(BaseModel):
|
class PostTarget(BaseModel):
|
||||||
server: str
|
server: str
|
||||||
|
@ -17,6 +20,7 @@ class PostTarget(BaseModel):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
guilds = [guild for guild in client.guilds if guild.name == self.server]
|
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
|
assert len(guilds) == 1
|
||||||
|
|
||||||
channels = [
|
channels = [
|
||||||
|
@ -25,11 +29,13 @@ class PostTarget(BaseModel):
|
||||||
if isinstance(channel, discord.TextChannel | discord.ForumChannel)
|
if isinstance(channel, discord.TextChannel | discord.ForumChannel)
|
||||||
and channel.name == self.channel
|
and channel.name == self.channel
|
||||||
]
|
]
|
||||||
|
_logger.debug(f"channels: {[channel.name for channel in channels]}")
|
||||||
assert len(channels) == 1
|
assert len(channels) == 1
|
||||||
|
|
||||||
threads = [
|
threads = [
|
||||||
thread for thread in channels[0].threads if thread.name == self.thread
|
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
|
assert len(threads) == 1
|
||||||
|
|
||||||
return threads[0]
|
return threads[0]
|
||||||
|
|
|
@ -73,7 +73,7 @@ class PostModal(ui.Modal, title="Post verfassen"):
|
||||||
if view.action is Action.PUBLISH:
|
if view.action is Action.PUBLISH:
|
||||||
# Post veröffentlichen
|
# Post veröffentlichen
|
||||||
_logger.info(
|
_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)
|
target = CONFIG.post.target.get(interaction.client)
|
||||||
await target.send(post_content)
|
await target.send(post_content)
|
||||||
|
@ -97,7 +97,7 @@ async def post(interaction: discord.Interaction):
|
||||||
|
|
||||||
if interaction.user.id in CONFIG.post.users:
|
if interaction.user.id in CONFIG.post.users:
|
||||||
# Verfassen-Dialog anzeigen
|
# Verfassen-Dialog anzeigen
|
||||||
_logger.info(
|
_logger.debug(
|
||||||
f"User {interaction.user.name}({interaction.user.id}) started a /post"
|
f"User {interaction.user.name}({interaction.user.id}) started a /post"
|
||||||
)
|
)
|
||||||
await interaction.response.send_modal(PostModal())
|
await interaction.response.send_modal(PostModal())
|
||||||
|
|
Loading…
Reference in a new issue