From dae89fd1ac12562a5b0ec3a3ad3229b0141e7869 Mon Sep 17 00:00:00 2001 From: kku Date: Mon, 10 Feb 2025 12:50:56 +0100 Subject: [PATCH] Removed warnings functionality --- classes/holo_user.py | 40 +++------------------------------------- modules/database.py | 2 -- validation/warnings.json | 18 ------------------ 3 files changed, 3 insertions(+), 57 deletions(-) delete mode 100644 validation/warnings.json diff --git a/classes/holo_user.py b/classes/holo_user.py index a4c2506..2d08564 100644 --- a/classes/holo_user.py +++ b/classes/holo_user.py @@ -6,11 +6,10 @@ from bson import ObjectId from discord import User, Member from libbot.utils import config_get from pymongo.results import InsertOneResult -from typing_extensions import deprecated from classes.cache import HoloCache from errors import UserNotFoundError -from modules.database import col_warnings, col_users +from modules.database import col_users logger: Logger = logging.getLogger(__name__) @@ -71,40 +70,7 @@ class HoloUser: @classmethod async def from_id(cls, user_id: int) -> "HoloUser": - return NotImplemented - - # TODO Deprecate and remove warnings - @deprecated("Warnings are deprecated") - async def get_warnings(self) -> int: - """Get number of warnings user has - - ### Returns: - * `int`: Number of warnings - """ - warns: Dict[str, Any] | None = await col_warnings.find_one({"id": self.id}) - - return 0 if warns is None else warns["warns"] - - # TODO Deprecate and remove warnings - @deprecated("Warnings are deprecated") - async def warn(self, count: int = 1, reason: str = "Reason not provided") -> None: - """Warn and add count to warns number - - ### Args: - * `count` (int, optional): Count of warnings to be added. Defaults to 1. - * `reason` (int, optional): Count of warnings to be added. Defaults to 1. - """ - warns: Dict[str, Any] | None = await col_warnings.find_one({"id": self.id}) - - if warns is not None: - await col_warnings.update_one( - {"_id": self._id}, - {"$set": {"warns": warns["warns"] + count}}, - ) - else: - await col_warnings.insert_one(document={"id": self.id, "warns": count}) - - logger.info("User %s was warned %s times due to: %s", self.id, count, reason) + raise NotImplementedError() async def _set(self, key: str, value: Any, cache: HoloCache | None = None) -> None: """Set attribute data and save it into the database @@ -209,7 +175,7 @@ class HoloUser: await self._remove("custom_role", cache=cache) async def purge(self, cache: HoloCache | None = None) -> None: - """Completely remove user data from database. Will not remove transactions logs and warnings. + """Completely remove user data from database. Only removes the user record from users collection. ### Args: * `cache` (HoloCache | None, optional): Cache engine to write the update into diff --git a/modules/database.py b/modules/database.py index fb62da4..97bf49a 100644 --- a/modules/database.py +++ b/modules/database.py @@ -29,14 +29,12 @@ db_client_sync: MongoClient = MongoClient(con_string) db: AsyncDatabase = db_client.get_database(name=db_config["name"]) col_users: AsyncCollection = db.get_collection("users") -col_warnings: AsyncCollection = db.get_collection("warnings") col_analytics: AsyncCollection = db.get_collection("analytics") # Sync declarations as a fallback sync_db: Database = db_client_sync.get_database(name=db_config["name"]) sync_col_users: Collection = sync_db.get_collection("users") -sync_col_warnings: Collection = sync_db.get_collection("warnings") sync_col_analytics: Collection = sync_db.get_collection("analytics") # Update indexes diff --git a/validation/warnings.json b/validation/warnings.json deleted file mode 100644 index 23596ea..0000000 --- a/validation/warnings.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "$jsonSchema": { - "required": [ - "user_id", - "warnings" - ], - "properties": { - "user_id": { - "bsonType": "long", - "description": "Discord ID of user" - }, - "warnings": { - "bsonType": "int", - "description": "Number of warnings on count" - } - } - } -} \ No newline at end of file