Added warning commands #35
This commit is contained in:
@@ -21,7 +21,7 @@ from bot_data.abc.user_message_count_per_hour_repository_abc import (
|
||||
UserMessageCountPerHourRepositoryABC,
|
||||
)
|
||||
from bot_data.abc.user_repository_abc import UserRepositoryABC
|
||||
from bot_data.abc.user_warning_repository_abc import UserWarningsRepositoryABC
|
||||
from bot_data.abc.user_warnings_repository_abc import UserWarningsRepositoryABC
|
||||
from bot_data.service.api_key_repository_service import ApiKeyRepositoryService
|
||||
from bot_data.service.auth_user_repository_service import AuthUserRepositoryService
|
||||
from bot_data.service.auto_role_repository_service import AutoRoleRepositoryService
|
||||
|
@@ -21,10 +21,12 @@ class UserWarningMigration(MigrationABC):
|
||||
CREATE TABLE IF NOT EXISTS `UserWarnings` (
|
||||
`Id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`Description` VARCHAR(255) NOT NULL,
|
||||
`UserId` BIGINT NOT NULL,
|
||||
`Author` BIGINT NULL,
|
||||
`CreatedAt` DATETIME(6),
|
||||
`LastModifiedAt` DATETIME(6),
|
||||
PRIMARY KEY(`Id`),
|
||||
FOREIGN KEY (`UserId`) REFERENCES `Users`(`UserId`),
|
||||
FOREIGN KEY (`Author`) REFERENCES `Users`(`UserId`)
|
||||
);
|
||||
"""
|
||||
|
@@ -11,7 +11,7 @@ class UserWarnings(TableABC):
|
||||
def __init__(
|
||||
self,
|
||||
description: str,
|
||||
user: Optional[User],
|
||||
user: User,
|
||||
author: Optional[User],
|
||||
created_at: datetime = None,
|
||||
modified_at: datetime = None,
|
||||
@@ -34,6 +34,10 @@ class UserWarnings(TableABC):
|
||||
def description(self) -> str:
|
||||
return self._description
|
||||
|
||||
@property
|
||||
def user(self) -> User:
|
||||
return self._user
|
||||
|
||||
@property
|
||||
def author(self) -> Optional[User]:
|
||||
return self._author
|
||||
@@ -51,7 +55,7 @@ class UserWarnings(TableABC):
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `UserWarnings`
|
||||
WHERE `UserWarnings` = {id};
|
||||
WHERE `Id` = {id};
|
||||
"""
|
||||
)
|
||||
|
||||
|
@@ -4,8 +4,9 @@ from cpl_core.database.context import DatabaseContextABC
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_core.logging.database_logger import DatabaseLogger
|
||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||
from bot_data.abc.user_repository_abc import UserRepositoryABC
|
||||
from bot_data.abc.user_warning_repository_abc import UserWarningsRepositoryABC
|
||||
from bot_data.abc.user_warnings_repository_abc import UserWarningsRepositoryABC
|
||||
from bot_data.model.user_warnings import UserWarnings
|
||||
|
||||
|
||||
@@ -15,6 +16,7 @@ class UserWarningsRepositoryService(UserWarningsRepositoryABC):
|
||||
logger: DatabaseLogger,
|
||||
db_context: DatabaseContextABC,
|
||||
users: UserRepositoryABC,
|
||||
servers: ServerRepositoryABC,
|
||||
):
|
||||
self._logger = logger
|
||||
self._context = db_context
|
||||
@@ -30,12 +32,19 @@ class UserWarningsRepositoryService(UserWarningsRepositoryABC):
|
||||
return value
|
||||
|
||||
def _from_result(self, sql_result: tuple) -> UserWarnings:
|
||||
user = self._users.get_user_by_id(self._get_value_from_result(sql_result[2]))
|
||||
author = None
|
||||
author_id = self._get_value_from_result(sql_result[2])
|
||||
if author_id is not None:
|
||||
author = self._users.get_user_by_id(author_id)
|
||||
|
||||
return UserWarnings(
|
||||
self._get_value_from_result(sql_result[1]),
|
||||
self._get_value_from_result(sql_result[2]),
|
||||
self._get_value_from_result(sql_result[3]),
|
||||
user,
|
||||
author,
|
||||
self._get_value_from_result(sql_result[4]),
|
||||
self._get_value_from_result(sql_result[0]),
|
||||
self._get_value_from_result(sql_result[5]),
|
||||
id=self._get_value_from_result(sql_result[0]),
|
||||
)
|
||||
|
||||
def get_user_warnings(self) -> List[UserWarnings]:
|
||||
|
Reference in New Issue
Block a user