Improved some messages and prepared them for i18n

This commit is contained in:
2025-04-26 18:21:09 +02:00
parent a17b1cd768
commit ca1e47b55a
16 changed files with 167 additions and 172 deletions

View File

@@ -1,17 +1,17 @@
from datetime import datetime
from logging import Logger
from pathlib import Path
from typing import Any, override, List, Dict
from typing import Any, Dict, List, override
from zoneinfo import ZoneInfo
from bson import ObjectId
from discord import Guild, User, TextChannel, Attachment, File
from discord import Attachment, File, Guild, TextChannel, User
from libbot.cache.classes import CacheMemcached, CacheRedis
from libbot.cache.manager import create_cache_client
from libbot.pycord.classes import PycordBot as LibPycordBot
from classes import PycordEvent, PycordEventStage, PycordGuild, PycordUser
from modules.database import col_users, col_events
from modules.database import col_events, col_users
from modules.utils import get_logger
logger: Logger = get_logger(__name__)
@@ -53,9 +53,7 @@ class PycordBot(LibPycordBot):
await super().close(**kwargs)
async def _schedule_tasks(self) -> None:
self.scheduler.add_job(
self._execute_event_controller, trigger="cron", minute="*/1", id="event_controller"
)
self.scheduler.add_job(self._execute_event_controller, trigger="cron", minute="*/1", id="event_controller")
async def _execute_event_controller(self) -> None:
await self._process_events_start()
@@ -105,9 +103,7 @@ class PycordBot(LibPycordBot):
first_stage_files: List[File] | None = first_stage.get_media_files()
await user_channel.send(
f"First stage...\n\n{first_stage.question}", files=first_stage_files
)
await user_channel.send(f"First stage...\n\n{first_stage.question}", files=first_stage_files)
# TODO Make a nice message
await self.notify_admins(
@@ -126,7 +122,7 @@ class PycordBot(LibPycordBot):
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)
stages: List[PycordEventStage] = await self.get_event_stages(event)
# TODO Make a nice message
stages_string: str = "\n\n".join(
@@ -174,7 +170,8 @@ class PycordBot(LibPycordBot):
return users
async def _get_event_stages(self, event: PycordEvent) -> List[PycordEventStage]:
# TODO Add documentation
async def get_event_stages(self, event: PycordEvent) -> List[PycordEventStage]:
return [(await self.find_event_stage(stage_id)) for stage_id in event.stage_ids]
# TODO Add documentation
@@ -254,9 +251,7 @@ class PycordBot(LibPycordBot):
return event_stage
# TODO Document this method
async def find_event(
self, event_id: str | ObjectId | None = None, event_name: str | None = None
) -> PycordEvent:
async def find_event(self, event_id: str | ObjectId | None = None, event_name: str | None = None) -> PycordEvent:
if event_id is None and event_name is None:
raise AttributeError("Either event's ID or name must be provided!")

View File

@@ -286,9 +286,7 @@ class PycordEvent:
stage_index: int = self.stage_ids.index(event_stage_id)
old_stage_index: int = old_stage_ids.index(event_stage_id)
logger.debug(
"Indexes for %s: was %s and is now %s", event_stage_id, old_stage_index, stage_index
)
logger.debug("Indexes for %s: was %s and is now %s", event_stage_id, old_stage_index, stage_index)
if stage_index != old_stage_index:
await (await bot.find_event_stage(event_stage_id)).update(cache, sequence=stage_index)

View File

@@ -4,7 +4,15 @@ from logging import Logger
from typing import Any, Dict, List, Optional
from bson import ObjectId
from discord import Bot, Guild, Member, PermissionOverwrite, TextChannel, Forbidden, Role
from discord import (
Bot,
Forbidden,
Guild,
Member,
PermissionOverwrite,
Role,
TextChannel,
)
from discord.abc import GuildChannel
from libbot.cache.classes import Cache
from pymongo.results import InsertOneResult
@@ -106,12 +114,8 @@ class PycordUser:
"guild_id": self.guild_id,
"event_channels": self.event_channels,
"is_jailed": self.is_jailed,
"current_event_id": (
self.current_event_id if not json_compatible else str(self.current_event_id)
),
"current_stage_id": (
self.current_stage_id if not json_compatible else str(self.current_stage_id)
),
"current_event_id": (self.current_event_id if not json_compatible else str(self.current_event_id)),
"current_stage_id": (self.current_stage_id if not json_compatible else str(self.current_stage_id)),
"registered_event_ids": (
self.registered_event_ids
if not json_compatible
@@ -367,9 +371,7 @@ class PycordUser:
# TODO Add documentation
async def set_event_stage(self, stage_id: str | ObjectId | None, cache: Optional[Cache] = None) -> None:
await self._set(
cache, current_stage_id=stage_id if isinstance(stage_id, str) else ObjectId(stage_id)
)
await self._set(cache, current_stage_id=stage_id if isinstance(stage_id, str) else ObjectId(stage_id))
async def jail(self, cache: Optional[Cache] = None) -> None:
await self._set(cache, is_jailed=True)