Added birthday to wi #401

This commit is contained in:
2023-10-10 18:50:20 +02:00
parent 61bdc8a52a
commit 7aff767a4b
27 changed files with 449 additions and 148 deletions

View File

@@ -9,6 +9,7 @@ type ServerConfig implements TableWithHistoryQuery {
xpPerOntimeHour: Int
xpPerEventParticipation: Int
xpPerAchievement: Int
xpForBirthday: Int
afkCommandChannelId: String
helpVoiceChannelId: String
teamChannelId: String
@@ -41,6 +42,7 @@ type ServerConfigHistory implements HistoryTableQuery {
xpPerOntimeHour: Int
xpPerEventParticipation: Int
xpPerAchievement: Int
xpForBirthday: Int
afkCommandChannelId: String
helpVoiceChannelId: String
teamChannelId: String
@@ -91,6 +93,7 @@ input ServerConfigInput {
xpPerOntimeHour: Int
xpPerEventParticipation: Int
xpPerAchievement: Int
xpForBirthday: Int
afkCommandChannelId: String
helpVoiceChannelId: String
teamChannelId: String

View File

@@ -5,6 +5,7 @@ type User implements TableWithHistoryQuery {
xp: Int
messageCount: Int
reactionCount: Int
birthday: String
ontime: Float
level: Level
@@ -62,6 +63,7 @@ type UserMutation {
input UserInput {
id: ID
xp: Int
birthday: String
levelId: ID
userWarnings: [UserWarningInput]
}

View File

@@ -1,6 +1,9 @@
from datetime import datetime
from cpl_core.database.context import DatabaseContextABC
from cpl_discord.service import DiscordBotServiceABC
from bot_api.route.route import Route
from bot_data.abc.level_repository_abc import LevelRepositoryABC
from bot_data.abc.server_repository_abc import ServerRepositoryABC
from bot_data.abc.user_repository_abc import UserRepositoryABC
@@ -42,18 +45,26 @@ class UserMutation(QueryABC):
def resolve_update_user(self, *_, input: dict):
user = self._users.get_user_by_id(input["id"])
self._can_user_mutate_data(user.server, UserRoleEnum.moderator)
new_xp = None
if "levelId" in input:
level = self._levels.get_level_by_id(input["levelId"])
if user.level.id != level.id:
new_xp = level.min_xp
auth_user = Route.get_user()
member = self._bot.get_guild(user.server.discord_id).get_member(
auth_user.users.where(lambda x: x.server.id == user.server.id).single().discord_id
)
if member.id != user.discord_id:
self._can_user_mutate_data(user.server, UserRoleEnum.moderator)
user.xp = new_xp if new_xp is not None else input["xp"] if "xp" in input else user.xp
new_xp = None
if "levelId" in input:
level = self._levels.get_level_by_id(input["levelId"])
if user.level.id != level.id:
new_xp = level.min_xp
if "userWarnings" in input:
self._update_user_warning(user, input["userWarnings"])
if "userWarnings" in input:
self._update_user_warning(user, input["userWarnings"])
user.xp = new_xp if new_xp is not None else input["xp"] if "xp" in input else user.xp
user.birthday = datetime.strptime(input["birthday"], "%d.%m.%Y") if "birthday" in input else user.birthday
self._users.update_user(user)
self._db.save_changes()

View File

@@ -20,6 +20,7 @@ class ServerConfigQuery(DataQueryWithHistoryABC):
self.set_field("xpPerOntimeHour", lambda config, *_: config.xp_per_ontime_hour)
self.set_field("xpPerEventParticipation", lambda config, *_: config.xp_per_event_participation)
self.set_field("xpPerAchievement", lambda config, *_: config.xp_per_achievement)
self.set_field("xpForBirthday", lambda config, *_: config.xp_for_birthday)
self.set_field("afkCommandChannelId", lambda config, *_: config.afk_command_channel_id)
self.set_field("helpVoiceChannelId", lambda config, *_: config.help_voice_channel_id)
self.set_field("teamChannelId", lambda config, *_: config.team_channel_id)

View File

@@ -50,6 +50,7 @@ class UserQuery(DataQueryWithHistoryABC):
self.set_field("xp", self.resolve_xp)
self.set_field("messageCount", lambda x, *_: x.message_count)
self.set_field("reactionCount", lambda x, *_: x.reaction_count)
self.set_field("birthday", lambda x, *_: x.birthday)
self.set_field("ontime", self.resolve_ontime)
self.set_field("level", self.resolve_level)
self.add_collection(