WIP: Bonus XP wenn man an einem Event teilnimmt #167 #201

Closed
edraft wants to merge 12 commits from #167 into 1.0.0
6 changed files with 65 additions and 9 deletions
Showing only changes of commit 2ef4d079ed - Show all commits

View File

@ -33,5 +33,20 @@ class UserJoinedGameServerMigration(MigrationABC):
)
)
self._cursor.execute(
str(
f"""
ALTER TABLE Users ADD MinecraftId VARCHAR(255) NULL AFTER XP;
"""
)
)
def downgrade(self):
self._cursor.execute("DROP TABLE `UserJoinedGameServer`;")
self._cursor.execute(
str(
f"""
ALTER TABLE Users DROP COLUMN MinecraftId;
"""
)
)

View File

@ -11,6 +11,7 @@ class User(TableABC):
self,
dc_id: int,
xp: int,
minecraft_id: Optional[str],
server: Optional[Server],
created_at: datetime = None,
modified_at: datetime = None,
@ -19,6 +20,7 @@ class User(TableABC):
self._user_id = id
self._discord_id = dc_id
self._xp = xp
self._minecraft_id = minecraft_id
self._server = server
TableABC.__init__(self)
@ -42,6 +44,10 @@ class User(TableABC):
self._modified_at = datetime.now().isoformat()
self._xp = value
@property
def minecraft_id(self) -> Optional[str]:
return self._minecraft_id
@property
def server(self) -> Optional[Server]:
return self._server
@ -96,10 +102,11 @@ class User(TableABC):
return str(
f"""
INSERT INTO `Users` (
`DiscordId`, `XP`, `ServerId`, `CreatedAt`, `LastModifiedAt`
`DiscordId`, `XP`, `MinecraftId`, `ServerId`, `CreatedAt`, `LastModifiedAt`
) VALUES (
{self._discord_id},
{self._xp},
'{"NULL" if self._minecraft_id is None else self._minecraft_id}',
{self._server.server_id},
'{self._created_at}',
'{self._modified_at}'
@ -113,6 +120,7 @@ class User(TableABC):
f"""
UPDATE `Users`
SET `XP` = {self._xp},
`MinecraftId` = '{"NULL" if self._minecraft_id is None else self._minecraft_id}',
`LastModifiedAt` = '{self._modified_at}'
WHERE `UserId` = {self._user_id};
"""

View File

@ -33,7 +33,10 @@ class UserRepositoryService(UserRepositoryABC):
User(
result[1],
result[2],
self._servers.get_server_by_id(result[3]),
result[3],
self._servers.get_server_by_id(result[4]),
result[5],
result[6],
id=result[0],
)
)
@ -47,7 +50,10 @@ class UserRepositoryService(UserRepositoryABC):
return User(
result[1],
result[2],
self._servers.get_server_by_id(result[3]),
result[3],
self._servers.get_server_by_id(result[4]),
result[5],
result[6],
id=result[0],
)
@ -62,7 +68,10 @@ class UserRepositoryService(UserRepositoryABC):
return User(
result[1],
result[2],
self._servers.get_server_by_id(result[3]),
result[3],
self._servers.get_server_by_id(result[4]),
result[5],
result[6],
id=result[0],
)
@ -78,7 +87,10 @@ class UserRepositoryService(UserRepositoryABC):
User(
result[1],
result[2],
self._servers.get_server_by_id(result[3]),
result[3],
self._servers.get_server_by_id(result[4]),
result[5],
result[6],
id=result[0],
)
)
@ -97,7 +109,10 @@ class UserRepositoryService(UserRepositoryABC):
User(
result[1],
result[2],
self._servers.get_server_by_id(result[3]),
result[3],
self._servers.get_server_by_id(result[4]),
result[5],
result[6],
id=result[0],
)
)
@ -114,7 +129,10 @@ class UserRepositoryService(UserRepositoryABC):
return User(
result[1],
result[2],
self._servers.get_server_by_id(result[3]),
result[3],
self._servers.get_server_by_id(result[4]),
result[5],
result[6],
id=result[0],
)
@ -132,9 +150,10 @@ class UserRepositoryService(UserRepositoryABC):
return User(
result[1],
result[2],
self._servers.get_server_by_id(result[3]),
result[4],
result[3],
self._servers.get_server_by_id(result[4]),
result[5],
result[6],
id=result[0],
)

View File

@ -30,6 +30,7 @@ class UserFilter(FilterABC):
self._discord_id = None
self._name = None
self._xp = None
self._minecraft_id = None
self._ontime = None
self._level: Optional[LevelFilter] = None
@ -46,6 +47,9 @@ class UserFilter(FilterABC):
if "xp" in values:
self._xp = int(values["xp"])
if "minecraftId" in values:
self._minecraft_id = values["minecraftId"]
if "ontime" in values:
self._ontime = int(values["ontime"])
@ -75,6 +79,9 @@ class UserFilter(FilterABC):
if self._xp is not None:
query = query.where(lambda x: x.xp == self._xp)
if self._minecraft_id is not None:
query = query.where(lambda x: x.minecraft_id == self._minecraft_id)
if self._ontime is not None:
query = query.where(lambda x: self._client_utils.get_ontime_for_user(x) == self._ontime)

View File

@ -3,6 +3,7 @@ type User implements TableQuery {
discordId: String
name: String
xp: Int
minecraftId: String
ontime: Float
level: Level
@ -26,6 +27,7 @@ input UserFilter {
discordId: String
name: String
xp: Int
minecraftId: String
ontime: Float
level: LevelFilter
server: ServerFilter

View File

@ -35,6 +35,7 @@ class UserQuery(DataQueryABC):
self.set_field("discordId", self.resolve_discord_id)
self.set_field("name", self.resolve_name)
self.set_field("xp", self.resolve_xp)
self.set_field("minecraftId", self.resolve_minecraft_id)
self.set_field("ontime", self.resolve_ontime)
self.set_field("level", self.resolve_level)
self.add_collection(
@ -71,6 +72,10 @@ class UserQuery(DataQueryABC):
def resolve_xp(user: User, *_):
return user.xp
@staticmethod
def resolve_minecraft_id(user: User, *_):
return user.minecraft_id
def resolve_ontime(self, user: User, *_):
return self._client_utils.get_ontime_for_user(user)