Added helper functions to append client values
This commit is contained in:
parent
e34fbb60aa
commit
be5567c1fd
@ -37,5 +37,17 @@ class ClientRepositoryABC(ABC):
|
||||
@abstractmethod
|
||||
def delete_client(self, client: Client): pass
|
||||
|
||||
@abstractmethod
|
||||
def apppend_sent_message_count(self, id: int, server_id: int, value: int): pass
|
||||
|
||||
@abstractmethod
|
||||
def apppend_received_message_count(self, id: int, server_id: int, value: int): pass
|
||||
|
||||
@abstractmethod
|
||||
def apppend_deleted_message_count(self, id: int, server_id: int, value: int): pass
|
||||
|
||||
@abstractmethod
|
||||
def apppend_received_command_count(self, id: int, server_id: int, value: int): pass
|
||||
|
||||
@abstractmethod
|
||||
def apppend_moved_users_count(self, id: int, server_id: int, value: int): pass
|
||||
|
@ -134,7 +134,7 @@ class ClientRepositoryService(ClientRepositoryABC):
|
||||
self._logger.trace(__name__, f'Send SQL command: {client.delete_string}')
|
||||
self._context.cursor.execute(client.delete_string)
|
||||
|
||||
def apppend_received_message_count(self, id: int, server_id: int, value: int):
|
||||
def _get_client_and_server(self, id: int, server_id: int) -> Client:
|
||||
server = self._servers.find_server_by_discord_id(server_id)
|
||||
if server is None:
|
||||
self._logger.warn(__name__, f'Cannot find server by id {server_id}')
|
||||
@ -145,5 +145,27 @@ class ClientRepositoryService(ClientRepositoryABC):
|
||||
self._logger.warn(__name__, f'Cannot find client by ids {id}@{server.server_id}')
|
||||
raise Exception('Value not found')
|
||||
|
||||
client.received_message_count += 1
|
||||
def apppend_sent_message_count(self, id: int, server_id: int, value: int):
|
||||
client = self._get_client_and_server(id, server_id)
|
||||
client.sent_message_count += value
|
||||
self.update_client(client)
|
||||
|
||||
def apppend_received_message_count(self, id: int, server_id: int, value: int):
|
||||
client = self._get_client_and_server(id, server_id)
|
||||
client.received_message_count += value
|
||||
self.update_client(client)
|
||||
|
||||
def apppend_deleted_message_count(self, id: int, server_id: int, value: int):
|
||||
client = self._get_client_and_server(id, server_id)
|
||||
client.deleted_message_count += value
|
||||
self.update_client(client)
|
||||
|
||||
def apppend_received_command_count(self, id: int, server_id: int, value: int):
|
||||
client = self._get_client_and_server(id, server_id)
|
||||
client.received_command_count += value
|
||||
self.update_client(client)
|
||||
|
||||
def apppend_moved_users_count(self, id: int, server_id: int, value: int):
|
||||
client = self._get_client_and_server(id, server_id)
|
||||
client.moved_users_count += value
|
||||
self.update_client(client)
|
||||
|
Reference in New Issue
Block a user