diff --git a/kdb-bot/src/bot_data/model/user_joined_voice_channel.py b/kdb-bot/src/bot_data/model/user_joined_voice_channel.py index 87cd7aeb..457c9fc1 100644 --- a/kdb-bot/src/bot_data/model/user_joined_voice_channel.py +++ b/kdb-bot/src/bot_data/model/user_joined_voice_channel.py @@ -45,6 +45,10 @@ class UserJoinedVoiceChannel(TableABC): def user(self) -> User: return self._user + @property + def time(self) -> float: + return round((self.leaved_on - self.joined_on).total_seconds() / 3600, 2) + @property def joined_on(self) -> datetime: return self._joined_on diff --git a/kdb-bot/src/bot_graphql/model/userJoinedVoiceChannel.gql b/kdb-bot/src/bot_graphql/model/userJoinedVoiceChannel.gql index d49f8c9e..7fb983b5 100644 --- a/kdb-bot/src/bot_graphql/model/userJoinedVoiceChannel.gql +++ b/kdb-bot/src/bot_graphql/model/userJoinedVoiceChannel.gql @@ -3,6 +3,7 @@ type UserJoinedVoiceChannel implements TableQuery { channelId: String channelName: String user: User + time: Float joinedOn: String leavedOn: String diff --git a/kdb-bot/src/bot_graphql/mutations/user_mutation.py b/kdb-bot/src/bot_graphql/mutations/user_mutation.py index 4a31a615..9356965b 100644 --- a/kdb-bot/src/bot_graphql/mutations/user_mutation.py +++ b/kdb-bot/src/bot_graphql/mutations/user_mutation.py @@ -37,12 +37,12 @@ class UserMutation(QueryABC): user = self._users.get_user_by_id(input["id"]) self._can_user_mutate_data(user.server, UserRoleEnum.moderator) - user.xp = input["xp"] if "xp" in input else user.xp - if "levelId" in input: level = self._levels.get_level_by_id(input["levelId"]) user.xp = level.min_xp + user.xp = input["xp"] if "xp" in input else user.xp + self._users.update_user(user) self._db.save_changes() self._level_service.set_level(user) diff --git a/kdb-bot/src/bot_graphql/queries/user_joined_voice_channel_query.py b/kdb-bot/src/bot_graphql/queries/user_joined_voice_channel_query.py index 333fbfa5..2640307d 100644 --- a/kdb-bot/src/bot_graphql/queries/user_joined_voice_channel_query.py +++ b/kdb-bot/src/bot_graphql/queries/user_joined_voice_channel_query.py @@ -14,6 +14,7 @@ class UserJoinedVoiceChannelQuery(DataQueryABC): self.set_field("channelId", self.resolve_channel_id) self.set_field("channelName", self.resolve_channel_name) self.set_field("user", self.resolve_user) + self.set_field("time", self.resolve_time) self.set_field("joinedOn", self.resolve_joined_on) self.set_field("leavedOn", self.resolve_leaved_on) @@ -33,6 +34,10 @@ class UserJoinedVoiceChannelQuery(DataQueryABC): def resolve_user(x: UserJoinedVoiceChannel, *_): return x.user + @staticmethod + def resolve_time(x: UserJoinedVoiceChannel, *_): + return x.time + @staticmethod def resolve_joined_on(x: UserJoinedVoiceChannel, *_): return x.joined_on diff --git a/kdb-bot/src/modules/base/events/base_on_voice_state_update_event.py b/kdb-bot/src/modules/base/events/base_on_voice_state_update_event.py index 8ff32383..c2a25a32 100644 --- a/kdb-bot/src/modules/base/events/base_on_voice_state_update_event.py +++ b/kdb-bot/src/modules/base/events/base_on_voice_state_update_event.py @@ -72,10 +72,8 @@ class BaseOnVoiceStateUpdateEvent(OnVoiceStateUpdateABC): join = self._user_joins_vc.get_active_user_joined_voice_channel_by_user_id(user.id) join.leaved_on = datetime.now() - # ontime as hours - ontime = round((join.leaved_on - join.joined_on).total_seconds() / 3600, 2) old_xp = user.xp - user.xp += round(ontime * settings.xp_per_ontime_hour) + user.xp += round(join.time * settings.xp_per_ontime_hour) self._user_joins_vc.update_user_joined_voice_channel(join) self._users.update_user(user) @@ -83,7 +81,7 @@ class BaseOnVoiceStateUpdateEvent(OnVoiceStateUpdateABC): self._logger.debug( __name__, - f"User {user} leaved_on {join.leaved_on}. Ontime: {ontime}h | xp: from {old_xp} to {user.xp}", + f"User {user} leaved_on {join.leaved_on}. Ontime: {join.time}h | xp: from {old_xp} to {user.xp}", ) except Exception as e: self._logger.error(__name__, f"Ontime validation failed", e) diff --git a/kdb-web/package.json b/kdb-web/package.json index 498f6a0f..a3642281 100644 --- a/kdb-web/package.json +++ b/kdb-web/package.json @@ -50,4 +50,4 @@ "tslib": "^2.4.1", "typescript": "~4.9.5" } -} +} \ No newline at end of file diff --git a/kdb-web/src/app/models/data/user.model.ts b/kdb-web/src/app/models/data/user.model.ts index 494ec567..385e6c6c 100644 --- a/kdb-web/src/app/models/data/user.model.ts +++ b/kdb-web/src/app/models/data/user.model.ts @@ -1,6 +1,8 @@ import { Data } from "./data.model"; import { Level, LevelFilter } from "./level.model"; import { Server, ServerFilter } from "./server.model"; +import { UserJoinedServer } from "./user_joined_server.model"; +import { UserJoinedVoiceChannel } from "./user_joined_voice_channel.model"; export interface User extends Data { id?: number; @@ -14,10 +16,10 @@ export interface User extends Data { leftServer?: boolean; joinedServerCount?: number; - joinedServers?: []; + joinedServers?: UserJoinedServer[]; joinedVoiceChannelCount?: number; - joinedVoiceChannels?: []; + joinedVoiceChannels?: UserJoinedVoiceChannel[]; userJoinedGameServerCount?: number; userJoinedGameServers?: []; diff --git a/kdb-web/src/app/models/data/user_joined_server.model.ts b/kdb-web/src/app/models/data/user_joined_server.model.ts new file mode 100644 index 00000000..7828dece --- /dev/null +++ b/kdb-web/src/app/models/data/user_joined_server.model.ts @@ -0,0 +1,9 @@ +import { Data } from "./data.model"; +import { User } from "./user.model"; + +export interface UserJoinedServer extends Data { + id: number; + user: User; + joinedOn: string; + leavedOn: string; +} diff --git a/kdb-web/src/app/models/data/user_joined_voice_channel.model.ts b/kdb-web/src/app/models/data/user_joined_voice_channel.model.ts new file mode 100644 index 00000000..9c49ff2e --- /dev/null +++ b/kdb-web/src/app/models/data/user_joined_voice_channel.model.ts @@ -0,0 +1,12 @@ +import { Data } from "./data.model"; +import { User } from "./user.model"; + +export interface UserJoinedVoiceChannel extends Data { + id: number; + channelId: string; + channelName: string; + user: User; + time: number; + joinedOn: string; + leavedOn: string; +} diff --git a/kdb-web/src/app/models/graphql/queries.model.ts b/kdb-web/src/app/models/graphql/queries.model.ts index 4fe54101..44756d56 100644 --- a/kdb-web/src/app/models/graphql/queries.model.ts +++ b/kdb-web/src/app/models/graphql/queries.model.ts @@ -78,4 +78,53 @@ export class Queries { } } `; + + static singleUserQuery = ` + query singleUserQuery($filter: UserFilter) { + users(filter: $filter) { + id + discordId + name + xp + ontime + level { + id + name + } + leftServer + server { + id + name + } + + joinedServerCount + joinedServers { + id + joinedOn + leavedOn + } + + joinedVoiceChannelCount + joinedVoiceChannels { + id + channelId + channelName + time + joinedOn + leavedOn + } + + userJoinedGameServerCount + userJoinedGameServers { + id + gameServer + joinedOn + leavedOn + } + + createdAt + modifiedAt + } + } + `; } diff --git a/kdb-web/src/app/modules/admin/auth-users/components/auth-user/auth-user.component.html b/kdb-web/src/app/modules/admin/auth-users/components/auth-user/auth-user.component.html index 29e5916b..bcb77b39 100644 --- a/kdb-web/src/app/modules/admin/auth-users/components/auth-user/auth-user.component.html +++ b/kdb-web/src/app/modules/admin/auth-users/components/auth-user/auth-user.component.html @@ -70,6 +70,18 @@ +
profile works!
+