Improved error handling; Introduced i18n for /register, /unregister and /guess

This commit is contained in:
2025-04-29 13:50:38 +02:00
parent 28d6340847
commit 9d39b803f3
8 changed files with 177 additions and 76 deletions

View File

@@ -5,6 +5,7 @@ from typing import Any, Dict, List, Optional
from zoneinfo import ZoneInfo
from bson import ObjectId
from bson.errors import InvalidId
from discord import Attachment, File, Guild, TextChannel, User
from libbot.cache.classes import CacheMemcached, CacheRedis
from libbot.cache.manager import create_cache_client
@@ -12,7 +13,12 @@ from libbot.pycord.classes import PycordBot as LibPycordBot
from typing_extensions import override
from classes import PycordEvent, PycordEventStage, PycordGuild, PycordUser
from classes.errors import EventStageMissingSequenceError
from classes.errors import (
EventStageMissingSequenceError,
GuildNotFoundError,
EventStageNotFoundError,
EventNotFoundError,
)
from modules.database import col_events, col_users
from modules.utils import get_logger
@@ -82,7 +88,12 @@ class PycordBot(LibPycordBot):
# Process each event
for event in events:
guild: Guild = self.get_guild(event.guild_id)
pycord_guild: PycordGuild = await self.find_guild(guild)
try:
pycord_guild: PycordGuild = await self.find_guild(guild)
except (InvalidId, GuildNotFoundError) as exc:
logger.error("Could not find guild %s (%s) due to: %s.", guild, guild.id, exc_info=exc)
continue
if len(event.stage_ids) == 0:
# TODO Make a nice message for management
@@ -172,8 +183,23 @@ class PycordBot(LibPycordBot):
# Process each event
for event in events:
guild: Guild = self.get_guild(event.guild_id)
pycord_guild: PycordGuild = await self.find_guild(guild)
stages: List[PycordEventStage] = await self.get_event_stages(event)
try:
pycord_guild: PycordGuild = await self.find_guild(guild)
except (InvalidId, GuildNotFoundError) as exc:
logger.error("Could not find guild %s (%s) due to: %s.", guild, guild.id, exc_info=exc)
continue
try:
stages: List[PycordEventStage] = await self.get_event_stages(event)
except (InvalidId, EventNotFoundError, EventStageNotFoundError) as exc:
logger.error(
"Could not event stages of the event %s (%s) due to: %s.",
event,
event._id,
exc_info=exc,
)
continue
# TODO Make a nice message
stages_string: str = "\n\n".join(