157 lines
4.7 KiB
Python
157 lines
4.7 KiB
Python
from datetime import datetime
|
|
from cpl_core.database import TableABC
|
|
|
|
from gismo_data.model.server import Server
|
|
|
|
|
|
class Client(TableABC):
|
|
|
|
def __init__(self,
|
|
dc_id: int,
|
|
smc: int,
|
|
rmc: int,
|
|
dmc: int,
|
|
rcc: int,
|
|
muc: int,
|
|
server: Server,
|
|
created_at: datetime = None,
|
|
modified_at: datetime = None,
|
|
id=0
|
|
):
|
|
self._client_id = id
|
|
self._discord_client_id = dc_id
|
|
self._sent_message_count = smc
|
|
self._received_message_count = rmc
|
|
self._deleted_message_count = dmc
|
|
self._received_command_count = rcc
|
|
self._moved_users_count = muc
|
|
self._server: Server = server
|
|
|
|
TableABC.__init__(self)
|
|
self._created_at = created_at if created_at is not None else self._created_at
|
|
self._modified_at = modified_at if modified_at is not None else self._modified_at
|
|
|
|
@property
|
|
def client_id(self) -> int:
|
|
return self._client_id
|
|
|
|
@property
|
|
def discord_id(self) -> int:
|
|
return self._discord_client_id
|
|
|
|
@property
|
|
def sent_message_count(self) -> int:
|
|
return self._sent_message_count
|
|
|
|
@property
|
|
def received_message_count(self) -> int:
|
|
return self._received_message_count
|
|
|
|
@property
|
|
def deleted_message_count(self) -> int:
|
|
return self._deleted_message_count
|
|
|
|
@property
|
|
def received_command_count(self) -> int:
|
|
return self._received_command_count
|
|
|
|
@property
|
|
def moved_users_count(self) -> int:
|
|
return self._moved_users_count
|
|
|
|
@property
|
|
def server(self) -> Server:
|
|
return self._server
|
|
|
|
@staticmethod
|
|
def get_create_string() -> str:
|
|
return str(f"""
|
|
CREATE TABLE IF NOT EXISTS `Clients` (
|
|
`ClientId` BIGINT NOT NULL AUTO_INCREMENT,
|
|
`DiscordClientId` BIGINT NOT NULL,
|
|
`SentMessageCount` BIGINT NOT NULL DEFAULT 0,
|
|
`ReceivedMessageCount` BIGINT NOT NULL DEFAULT 0,
|
|
`DeletedMessageCount` BIGINT NOT NULL DEFAULT 0,
|
|
`ReceivedCommandsCount` BIGINT NOT NULL DEFAULT 0,
|
|
`MovedUsersCount` BIGINT NOT NULL DEFAULT 0,
|
|
`ServerId` BIGINT,
|
|
`CreatedAt` DATETIME(6),
|
|
`LastModifiedAt` DATETIME(6),
|
|
FOREIGN KEY (`ServerId`) REFERENCES Servers(`ServerId`),
|
|
PRIMARY KEY(`ClientId`)
|
|
);
|
|
""")
|
|
|
|
@staticmethod
|
|
def get_select_all_string() -> str:
|
|
return str(f"""
|
|
SELECT * FROM `Clients`;
|
|
""")
|
|
|
|
@staticmethod
|
|
def get_select_by_id_string(id: int) -> str:
|
|
return str(f"""
|
|
SELECT * FROM `Clients`
|
|
WHERE `ClientId` = {id};
|
|
""")
|
|
|
|
@staticmethod
|
|
def get_select_by_discord_id_string(id: int) -> str:
|
|
return str(f"""
|
|
SELECT * FROM `Clients`
|
|
WHERE `DiscordClientId` = {id};
|
|
""")
|
|
|
|
@staticmethod
|
|
def get_select_by_server_id_string(id: int) -> str:
|
|
return str(f"""
|
|
SELECT * FROM `Clients`
|
|
WHERE `ServerId` = {id};
|
|
""")
|
|
|
|
@property
|
|
def insert_string(self) -> str:
|
|
return str(f"""
|
|
INSERT INTO `Clients` (
|
|
`DiscordClientId`,
|
|
`SentMessageCount`,
|
|
`ReceivedMessageCount`,
|
|
`DeletedMessageCount`,
|
|
`ReceivedCommandsCount`,
|
|
`MovedUsersCount`,
|
|
`ServerId`,
|
|
`CreatedAt`,
|
|
`LastModifiedAt`
|
|
) VALUES (
|
|
{self._discord_client_id},
|
|
{self._sent_message_count},
|
|
{self._received_message_count},
|
|
{self._deleted_message_count},
|
|
{self._received_message_count},
|
|
{self._moved_users_count},
|
|
{self._server.server_id},
|
|
'{self._created_at}',
|
|
'{self._modified_at}'
|
|
);
|
|
""")
|
|
|
|
@property
|
|
def udpate_string(self) -> str:
|
|
return str(f"""
|
|
UPDATE `Clients`
|
|
SET `SentMessageCount` = {self._sent_message_count},
|
|
`ReceivedMessageCount` = {self._received_message_count},
|
|
`DeletedMessageCount` = {self._deleted_message_count},
|
|
`ReceivedCommandsCount` = {self._received_command_count},
|
|
`MovedUsersCount` = {self._moved_users_count},
|
|
`LastModifiedAt` = '{self._modified_at}'
|
|
WHERE `Id` = {self._client_id};
|
|
""")
|
|
|
|
@property
|
|
def delete_string(self) -> str:
|
|
return str(f"""
|
|
DELETE FROM `Clients`
|
|
WHERE `Id` = {self._client_id};
|
|
""")
|