From 7a64e334d20d17c484644351fe46e0cc451c008a Mon Sep 17 00:00:00 2001 From: kku Date: Fri, 27 Dec 2024 20:42:12 +0100 Subject: [PATCH 1/3] Added logging for thread creation message deletion --- cogs/logger.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/cogs/logger.py b/cogs/logger.py index e16997a..54201e2 100644 --- a/cogs/logger.py +++ b/cogs/logger.py @@ -43,7 +43,18 @@ class Logger(commands.Cog): > 0 ) ): - await message.delete() + try: + logger.info( + "Deleting the thread creation message in a custom channel %s", + message.channel.id, + ) + await message.delete() + except Exception as exc: + logger.warning( + "Could not delete the thread creation message in a custom channel %s due to %s", + message.channel.id, + exc, + ) @commands.Cog.listener() async def on_member_join(self, member: Member) -> None: From ce57755eee00feacf391ef518dfcf1157303e7f6 Mon Sep 17 00:00:00 2001 From: kku Date: Fri, 27 Dec 2024 22:23:41 +0100 Subject: [PATCH 2/3] Improved type-hinting for loggers and removed legacy --- classes/holo_user.py | 8 ++------ cogs/admin.py | 3 ++- cogs/analytics.py | 3 ++- cogs/custom_channels.py | 3 ++- cogs/fun.py | 3 ++- cogs/logger.py | 3 ++- 6 files changed, 12 insertions(+), 11 deletions(-) diff --git a/classes/holo_user.py b/classes/holo_user.py index 0ebb2a9..508b8db 100644 --- a/classes/holo_user.py +++ b/classes/holo_user.py @@ -1,4 +1,5 @@ import logging +from logging import Logger from typing import Any, Dict from bson import ObjectId @@ -8,7 +9,7 @@ from libbot.utils import config_get from errors import UserNotFoundError from modules.database import col_warnings, sync_col_users, sync_col_warnings, col_users -logger = logging.getLogger(__name__) +logger: Logger = logging.getLogger(__name__) class HoloUser: @@ -123,8 +124,3 @@ class HoloUser: return True return False - - # def purge(self) -> None: - # """Completely remove data from database. Will not remove transactions logs and warnings.""" - # col_users.delete_one(filter={"_id": self.db_id}) - # self.unauthorize() diff --git a/cogs/admin.py b/cogs/admin.py index d6036aa..2d226a9 100644 --- a/cogs/admin.py +++ b/cogs/admin.py @@ -1,5 +1,6 @@ import logging import sys +from logging import Logger from discord import ( ApplicationContext, @@ -20,7 +21,7 @@ from modules.scheduler import scheduler from modules.utils_sync import guild_name from modules.waifu_pics import waifu_pics -logger = logging.getLogger(__name__) +logger: Logger = logging.getLogger(__name__) class Admin(commands.Cog): diff --git a/cogs/analytics.py b/cogs/analytics.py index b3a27c7..af5f951 100644 --- a/cogs/analytics.py +++ b/cogs/analytics.py @@ -1,4 +1,5 @@ import logging +from logging import Logger from typing import Dict, List, Any from discord import Cog, Message @@ -7,7 +8,7 @@ from discord.ext import commands from classes.holo_bot import HoloBot from modules.database import col_analytics -logger = logging.getLogger(__name__) +logger: Logger = logging.getLogger(__name__) class Analytics(commands.Cog): diff --git a/cogs/custom_channels.py b/cogs/custom_channels.py index 6a1651b..328ca08 100644 --- a/cogs/custom_channels.py +++ b/cogs/custom_channels.py @@ -1,4 +1,5 @@ import logging +from logging import Logger from typing import Any, Dict from discord import ApplicationContext, Embed, option, TextChannel, Role @@ -14,7 +15,7 @@ from enums import Color from modules.database import col_users from modules.utils_sync import guild_name -logger = logging.getLogger(__name__) +logger: Logger = logging.getLogger(__name__) class CustomChannels(commands.Cog): diff --git a/cogs/fun.py b/cogs/fun.py index bb2bc58..0de5956 100644 --- a/cogs/fun.py +++ b/cogs/fun.py @@ -1,4 +1,5 @@ import logging +from logging import Logger from discord import ApplicationContext, Embed, User, option, slash_command from discord.ext import commands @@ -8,7 +9,7 @@ from classes.holo_bot import HoloBot from modules.utils_sync import guild_name from modules.waifu_pics import waifu_pics -logger = logging.getLogger(__name__) +logger: Logger = logging.getLogger(__name__) class Fun(commands.Cog): diff --git a/cogs/logger.py b/cogs/logger.py index 54201e2..66904a4 100644 --- a/cogs/logger.py +++ b/cogs/logger.py @@ -1,4 +1,5 @@ import logging +from logging import Logger from typing import Dict, Any from discord import Member, Message, TextChannel, MessageType @@ -9,7 +10,7 @@ from libbot.utils import config_get from classes.holo_bot import HoloBot from modules.database import col_users -logger = logging.getLogger(__name__) +logger: Logger = logging.getLogger(__name__) class Logger(commands.Cog): From eb8019ccfe14d2415bb7e63eb2d039c7ce18d550 Mon Sep 17 00:00:00 2001 From: kku Date: Fri, 27 Dec 2024 22:33:58 +0100 Subject: [PATCH 3/3] Updated the documentation --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b7c196d..a0afa5e 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ ## Installation from release 1. Install MongoDB using the [official installation manual](https://www.mongodb.com/docs/manual/installation) -2. Install Python 3.9+ (3.11+ is recommended) +2. Install Python 3.11+ 3. Download the [latest release](https://git.end-play.xyz/HoloUA/Discord/releases/latest)'s archive 4. Extract the archive 5. Navigate to the extracted folder and subfolder `Discord` in it @@ -19,14 +19,14 @@ 7. Activate the virtual environment: Windows: `.venv\Scripts\activate.bat` Linux/macOS: `.venv/bin/activate` -8. Install dependencies: +8. Install the dependencies: `python -m pip install -r requirements.txt` 9. Run the bot with `python main.py` after completing the [configuration](#Configuration) ## Installation with Git 1. Install MongoDB using the [official installation manual](https://www.mongodb.com/docs/manual/installation) -2. Install Python 3.9+ (3.11+ is recommended) +2. Install Python 3.11+ 3. Clone the repository: `git clone https://git.end-play.xyz/HoloUA/Discord.git` 4. `cd Discord`