Removed warnings functionality
This commit is contained in:
parent
25f2595cf7
commit
dae89fd1ac
@ -6,11 +6,10 @@ from bson import ObjectId
|
|||||||
from discord import User, Member
|
from discord import User, Member
|
||||||
from libbot.utils import config_get
|
from libbot.utils import config_get
|
||||||
from pymongo.results import InsertOneResult
|
from pymongo.results import InsertOneResult
|
||||||
from typing_extensions import deprecated
|
|
||||||
|
|
||||||
from classes.cache import HoloCache
|
from classes.cache import HoloCache
|
||||||
from errors import UserNotFoundError
|
from errors import UserNotFoundError
|
||||||
from modules.database import col_warnings, col_users
|
from modules.database import col_users
|
||||||
|
|
||||||
logger: Logger = logging.getLogger(__name__)
|
logger: Logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -71,40 +70,7 @@ class HoloUser:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def from_id(cls, user_id: int) -> "HoloUser":
|
async def from_id(cls, user_id: int) -> "HoloUser":
|
||||||
return NotImplemented
|
raise NotImplementedError()
|
||||||
|
|
||||||
# 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)
|
|
||||||
|
|
||||||
async def _set(self, key: str, value: Any, cache: HoloCache | None = None) -> None:
|
async def _set(self, key: str, value: Any, cache: HoloCache | None = None) -> None:
|
||||||
"""Set attribute data and save it into the database
|
"""Set attribute data and save it into the database
|
||||||
@ -209,7 +175,7 @@ class HoloUser:
|
|||||||
await self._remove("custom_role", cache=cache)
|
await self._remove("custom_role", cache=cache)
|
||||||
|
|
||||||
async def purge(self, cache: HoloCache | None = None) -> None:
|
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:
|
### Args:
|
||||||
* `cache` (HoloCache | None, optional): Cache engine to write the update into
|
* `cache` (HoloCache | None, optional): Cache engine to write the update into
|
||||||
|
@ -29,14 +29,12 @@ db_client_sync: MongoClient = MongoClient(con_string)
|
|||||||
db: AsyncDatabase = db_client.get_database(name=db_config["name"])
|
db: AsyncDatabase = db_client.get_database(name=db_config["name"])
|
||||||
|
|
||||||
col_users: AsyncCollection = db.get_collection("users")
|
col_users: AsyncCollection = db.get_collection("users")
|
||||||
col_warnings: AsyncCollection = db.get_collection("warnings")
|
|
||||||
col_analytics: AsyncCollection = db.get_collection("analytics")
|
col_analytics: AsyncCollection = db.get_collection("analytics")
|
||||||
|
|
||||||
# Sync declarations as a fallback
|
# Sync declarations as a fallback
|
||||||
sync_db: Database = db_client_sync.get_database(name=db_config["name"])
|
sync_db: Database = db_client_sync.get_database(name=db_config["name"])
|
||||||
|
|
||||||
sync_col_users: Collection = sync_db.get_collection("users")
|
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")
|
sync_col_analytics: Collection = sync_db.get_collection("analytics")
|
||||||
|
|
||||||
# Update indexes
|
# Update indexes
|
||||||
|
@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user