1.1.0 #352

Merged
edraft merged 145 commits from 1.1.0 into master 2023-08-24 17:50:25 +02:00
3 changed files with 48 additions and 15 deletions
Showing only changes of commit fdbba1b89c - Show all commits

View File

@ -37,20 +37,26 @@ class AchievementsMigration(MigrationABC):
self._cursor.execute(
str(
f"""
ALTER TABLE Users ADD MessageCount BIGINT NOT NULL DEFAULT 0 AFTER XP;
ALTER TABLE Users ADD ReactionCount BIGINT NOT NULL DEFAULT 0 AFTER XP;
CREATE TABLE IF NOT EXISTS `AchievementsHistory`
(
`Id` BIGINT(20) NOT NULL,
`ServerId` BIGINT,
`Name` VARCHAR(255) NOT NULL,
`Attribute` VARCHAR(255) NOT NULL,
`Operator` VARCHAR(2) NOT NULL,
`Value` VARCHAR(255) NOT NULL,
`Deleted` BOOL DEFAULT FALSE,
`DateFrom` DATETIME(6) NOT NULL,
`DateTo` DATETIME(6) NOT NULL
);
"""
)
)
self._cursor.execute(
str(
f"""
ALTER TABLE UsersHistory ADD MessageCount BIGINT NOT NULL DEFAULT 0 AFTER XP;
ALTER TABLE UsersHistory ADD ReactionCount BIGINT NOT NULL DEFAULT 0 AFTER XP;
"""
)
)
self._cursor.execute(str(f"""ALTER TABLE Users ADD MessageCount BIGINT NOT NULL DEFAULT 0 AFTER XP;"""))
self._cursor.execute(str(f"""ALTER TABLE Users ADD ReactionCount BIGINT NOT NULL DEFAULT 0 AFTER XP;"""))
self._cursor.execute(str(f"""ALTER TABLE UsersHistory ADD MessageCount BIGINT NOT NULL DEFAULT 0 AFTER XP;"""))
self._cursor.execute(str(f"""ALTER TABLE UsersHistory ADD ReactionCount BIGINT NOT NULL DEFAULT 0 AFTER XP;"""))
self._cursor.execute(
str(
@ -85,7 +91,8 @@ class AchievementsMigration(MigrationABC):
);
END;
"""
)
),
multi=True,
)
def downgrade(self):

View File

@ -15,6 +15,8 @@ class User(TableABC):
self,
dc_id: int,
xp: int,
message_count: int,
reaction_count: int,
server: Optional[Server],
created_at: datetime = None,
modified_at: datetime = None,
@ -23,6 +25,8 @@ class User(TableABC):
self._user_id = id
self._discord_id = dc_id
self._xp = xp
self._message_count = message_count
self._reaction_count = reaction_count
self._server = server
TableABC.__init__(self)
@ -59,6 +63,22 @@ class User(TableABC):
def xp(self, value: int):
self._xp = value
@property
def message_count(self) -> int:
return self._message_count
@message_count.setter
def message_count(self, value: int):
self._message_count = value
@property
def reaction_count(self) -> int:
return self._reaction_count
@reaction_count.setter
def reaction_count(self, value: int):
self._reaction_count = value
@property
@ServiceProviderABC.inject
def ontime(self, services: ServiceProviderABC) -> float:
@ -151,10 +171,12 @@ class User(TableABC):
return str(
f"""
INSERT INTO `Users` (
`DiscordId`, `XP`, `ServerId`
`DiscordId`, `XP`, `MessageCount`, `ReactionCount`, `ServerId`
) VALUES (
{self._discord_id},
{self._xp},
{self._message_count},
{self._reaction_count},
{self._server.id}
);
"""
@ -165,7 +187,9 @@ class User(TableABC):
return str(
f"""
UPDATE `Users`
SET `XP` = {self._xp}
SET `XP` = {self._xp},
`MessageCount` = {self._message_count},
`ReactionCount` = {self._reaction_count}
WHERE `UserId` = {self._user_id};
"""
)

View File

@ -27,9 +27,11 @@ class UserRepositoryService(UserRepositoryABC):
return User(
result[1],
result[2],
self._servers.get_server_by_id(result[3]),
result[3],
result[4],
result[5],
self._servers.get_server_by_id(result[5]),
result[6],
result[7],
id=result[0],
)