From 2befa921eae57d09562d3974a1a9a9346ae38b44 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Wed, 12 Apr 2023 21:02:18 +0200 Subject: [PATCH 1/9] Added level on reaction handling #304 --- kdb-bot/src/bot/module_list.py | 2 +- .../events/level_on_raw_reaction_add_event.py | 34 +++++++++++++++++++ .../level_on_raw_reaction_remove_event.py | 34 +++++++++++++++++++ kdb-bot/src/modules/level/level_module.py | 4 +++ 4 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 kdb-bot/src/modules/level/events/level_on_raw_reaction_add_event.py create mode 100644 kdb-bot/src/modules/level/events/level_on_raw_reaction_remove_event.py diff --git a/kdb-bot/src/bot/module_list.py b/kdb-bot/src/bot/module_list.py index 120926ef..700f0c73 100644 --- a/kdb-bot/src/bot/module_list.py +++ b/kdb-bot/src/bot/module_list.py @@ -25,10 +25,10 @@ class ModuleList: DataModule, GraphQLModule, PermissionModule, - LevelModule, DatabaseModule, AutoRoleModule, BaseModule, + LevelModule, ApiModule, TechnicianModule, # has to be last! diff --git a/kdb-bot/src/modules/level/events/level_on_raw_reaction_add_event.py b/kdb-bot/src/modules/level/events/level_on_raw_reaction_add_event.py new file mode 100644 index 00000000..5535b0e7 --- /dev/null +++ b/kdb-bot/src/modules/level/events/level_on_raw_reaction_add_event.py @@ -0,0 +1,34 @@ +from cpl_core.logging import LoggerABC +from cpl_discord.events.on_raw_reaction_add_abc import OnRawReactionAddABC +from cpl_discord.service import DiscordBotServiceABC +from discord import RawReactionActionEvent + +from bot_core.helper.event_checks import EventChecks +from modules.level.service.level_service import LevelService + + +class LevelOnRawReactionAddEvent(OnRawReactionAddABC): + def __init__( + self, + logger: LoggerABC, + bot: DiscordBotServiceABC, + level: LevelService, + ): + OnRawReactionAddABC.__init__(self) + + self._logger = logger + self._bot = bot + self._level = level + + @EventChecks.check_is_ready() + async def on_raw_reaction_add(self, payload: RawReactionActionEvent): + self._logger.debug(__name__, f"Module {type(self)} started") + try: + self._logger.trace(__name__, f"Handle reaction {payload} for level") + + guild = self._bot.get_guild(payload.guild_id) + member = guild.get_member(payload.user_id) + + await self._level.check_level(member) + except Exception as e: + self._logger.error(__name__, f"Level check by message failed", e) diff --git a/kdb-bot/src/modules/level/events/level_on_raw_reaction_remove_event.py b/kdb-bot/src/modules/level/events/level_on_raw_reaction_remove_event.py new file mode 100644 index 00000000..3e4c32d7 --- /dev/null +++ b/kdb-bot/src/modules/level/events/level_on_raw_reaction_remove_event.py @@ -0,0 +1,34 @@ +from cpl_core.logging import LoggerABC +from cpl_discord.events.on_raw_reaction_remove_abc import OnRawReactionRemoveABC +from cpl_discord.service import DiscordBotServiceABC +from discord import RawReactionActionEvent + +from bot_core.helper.event_checks import EventChecks +from modules.level.service.level_service import LevelService + + +class LevelOnRawReactionRemoveEvent(OnRawReactionRemoveABC): + def __init__( + self, + logger: LoggerABC, + bot: DiscordBotServiceABC, + level: LevelService, + ): + OnRawReactionRemoveABC.__init__(self) + + self._logger = logger + self._bot = bot + self._level = level + + @EventChecks.check_is_ready() + async def on_raw_reaction_remove(self, payload: RawReactionActionEvent): + self._logger.debug(__name__, f"Module {type(self)} started") + try: + self._logger.trace(__name__, f"Handle reaction {payload} for level") + + guild = self._bot.get_guild(payload.guild_id) + member = guild.get_member(payload.user_id) + + await self._level.check_level(member) + except Exception as e: + self._logger.error(__name__, f"Level check by message failed", e) diff --git a/kdb-bot/src/modules/level/level_module.py b/kdb-bot/src/modules/level/level_module.py index be99518c..018377f9 100644 --- a/kdb-bot/src/modules/level/level_module.py +++ b/kdb-bot/src/modules/level/level_module.py @@ -12,6 +12,8 @@ from bot_data.abc.data_seeder_abc import DataSeederABC from modules.level.command.level_group import LevelGroup from modules.level.events.level_on_member_join_event import LevelOnMemberJoinEvent from modules.level.events.level_on_message_event import LevelOnMessageEvent +from modules.level.events.level_on_raw_reaction_add_event import LevelOnRawReactionAddEvent +from modules.level.events.level_on_raw_reaction_remove_event import LevelOnRawReactionRemoveEvent from modules.level.events.level_on_voice_state_update_event import ( LevelOnVoiceStateUpdateEvent, ) @@ -43,3 +45,5 @@ class LevelModule(ModuleABC): LevelOnVoiceStateUpdateEvent, ) self._dc.add_event(DiscordEventTypesEnum.on_member_join.value, LevelOnMemberJoinEvent) + self._dc.add_event(DiscordEventTypesEnum.on_raw_reaction_add.value, LevelOnRawReactionAddEvent) + self._dc.add_event(DiscordEventTypesEnum.on_raw_reaction_remove.value, LevelOnRawReactionRemoveEvent) -- 2.45.2 From 280b22af550cc1ad904eb1fe5d69ab09642b9bb8 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Wed, 12 Apr 2023 21:43:45 +0200 Subject: [PATCH 2/9] Fixed register re nav #306 --- .../forget-password/forget-password.component.ts | 2 +- .../auth/components/registration/registration.component.ts | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/kdb-web/src/app/modules/auth/components/forget-password/forget-password.component.ts b/kdb-web/src/app/modules/auth/components/forget-password/forget-password.component.ts index 66d570db..85b44e9b 100644 --- a/kdb-web/src/app/modules/auth/components/forget-password/forget-password.component.ts +++ b/kdb-web/src/app/modules/auth/components/forget-password/forget-password.component.ts @@ -40,7 +40,7 @@ export class ForgetPasswordComponent implements OnInit { ngOnInit(): void { this.spinnerService.showSpinner(); - if (!this.authService.isLoggedIn$.value) { + if (this.authService.isLoggedIn$.value) { this.router.navigate(["/dashboard"]); } diff --git a/kdb-web/src/app/modules/auth/components/registration/registration.component.ts b/kdb-web/src/app/modules/auth/components/registration/registration.component.ts index 86abe3b2..db52dfa5 100644 --- a/kdb-web/src/app/modules/auth/components/registration/registration.component.ts +++ b/kdb-web/src/app/modules/auth/components/registration/registration.component.ts @@ -49,7 +49,7 @@ export class RegistrationComponent implements OnInit, OnDestroy { private settings: SettingsService ) { this.spinnerService.showSpinner(); - if (!this.authService.isLoggedIn$.value) { + if (this.authService.isLoggedIn$.value) { this.router.navigate(["/dashboard"]); } this.spinnerService.hideSpinner(); @@ -57,7 +57,6 @@ export class RegistrationComponent implements OnInit, OnDestroy { ngOnInit(): void { this.translate.onLangChange.pipe(takeUntil(this.unsubscriber)).subscribe(lang => { - this.confirmPrivacyString = this.translate.instant("auth.register.confirm_privacy", { url: this.settings.getPrivacyURL() }); }); @@ -167,8 +166,4 @@ export class RegistrationComponent implements OnInit, OnDestroy { }); } } - - log($event: Event): void { - console.log($event); - } } -- 2.45.2 From 089de53136fe50010f6cfc172c5d9f03b49548d2 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Wed, 12 Apr 2023 22:04:49 +0200 Subject: [PATCH 3/9] Fixed is ready function #309 --- kdb-bot/src/bot_core/helper/event_checks.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/kdb-bot/src/bot_core/helper/event_checks.py b/kdb-bot/src/bot_core/helper/event_checks.py index dbf241ab..5639a3da 100644 --- a/kdb-bot/src/bot_core/helper/event_checks.py +++ b/kdb-bot/src/bot_core/helper/event_checks.py @@ -1,13 +1,9 @@ from typing import Optional -from cpl_translation import TranslatePipe from discord.ext import commands -from discord.ext.commands import Context from bot_core.abc.client_utils_abc import ClientUtilsABC -from bot_core.abc.message_service_abc import MessageServiceABC from bot_core.exception.check_error import CheckError -from modules.permission.abc.permission_service_abc import PermissionServiceABC class EventChecks: @@ -23,7 +19,7 @@ class EventChecks: @classmethod def check_is_ready(cls): async def check_if_bot_is_ready() -> bool: - result = await cls._client_utils.check_if_bot_is_ready() + result = await cls._client_utils.check_if_bot_is_ready_yet() if not result: raise CheckError(f"Bot is not ready") return result -- 2.45.2 From b8320c83fe90db85bc77ff57cd8c6d12640266b0 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Fri, 14 Apr 2023 21:09:03 +0200 Subject: [PATCH 4/9] Fixed closed navbar #307 --- kdb-web/src/app/services/sidebar/sidebar.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kdb-web/src/app/services/sidebar/sidebar.service.ts b/kdb-web/src/app/services/sidebar/sidebar.service.ts index 91da7e92..1bd9476a 100644 --- a/kdb-web/src/app/services/sidebar/sidebar.service.ts +++ b/kdb-web/src/app/services/sidebar/sidebar.service.ts @@ -37,7 +37,7 @@ export class SidebarService { ) { this.themeService.isSidebarOpen$.subscribe(value => { this.isSidebarOpen = value; - this.setMenu(); + this.setMenu(true); }); this.translateService.onLangChange.subscribe(_ => { -- 2.45.2 From 1ebad89c973f2818c212785ff346ca6692922861 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Fri, 14 Apr 2023 21:46:01 +0200 Subject: [PATCH 5/9] Improved members data loading #300 --- kdb-web/package.json | 2 +- kdb-web/src/app/models/data/user.model.ts | 11 ----- .../src/app/models/graphql/queries.model.ts | 35 ++++++++++++++- .../history-btn/history-btn.component.ts | 44 +++++++++++++++++-- .../auto-roles-rules.component.html | 2 +- .../auto-roles/auto-roles.component.html | 2 +- .../components/levels/levels.component.html | 2 +- .../server/members/members.component.html | 2 +- .../view/server/members/members.component.ts | 1 + .../view/server/profile/profile.component.ts | 6 +-- kdb-web/src/assets/config.json | 2 +- 11 files changed, 83 insertions(+), 26 deletions(-) diff --git a/kdb-web/package.json b/kdb-web/package.json index 4cff7843..44a55353 100644 --- a/kdb-web/package.json +++ b/kdb-web/package.json @@ -1,6 +1,6 @@ { "name": "kdb-web", - "version": "1.0.5", + "version": "1.0.dev307", "scripts": { "ng": "ng", "update-version": "ts-node-esm update-version.ts", diff --git a/kdb-web/src/app/models/data/user.model.ts b/kdb-web/src/app/models/data/user.model.ts index 671da870..fb36964e 100644 --- a/kdb-web/src/app/models/data/user.model.ts +++ b/kdb-web/src/app/models/data/user.model.ts @@ -23,17 +23,6 @@ export interface User extends DataWithHistory { userJoinedGameServerCount?: number; userJoinedGameServers?: UserJoinedGameServer[]; - - // history?: UserHistory[]; -} - -export interface UserHistory extends History { - id?: number; - discordId?: number; - xp?: number; - level?: number; - server?: number; - leftServer?: boolean; } export interface UserFilter { diff --git a/kdb-web/src/app/models/graphql/queries.model.ts b/kdb-web/src/app/models/graphql/queries.model.ts index 29b8dbcf..d55fef25 100644 --- a/kdb-web/src/app/models/graphql/queries.model.ts +++ b/kdb-web/src/app/models/graphql/queries.model.ts @@ -94,6 +94,29 @@ export class Queries { name } leftServer + + createdAt + modifiedAt + } + } + } + `; + + static userProfile = ` + query UserProfile($serverId: ID, $userId: ID, $page: Page, $sort: Sort) { + servers(filter: {id: $serverId}) { + userCount + users(filter: {id: $userId}, page: $page, sort: $sort) { + id + discordId + name + xp + ontime + level { + id + name + } + leftServer server { id name @@ -124,9 +147,17 @@ export class Queries { joinedOn leavedOn } + } + } + } + `; - createdAt - modifiedAt + static userQueryWithHistory = ` + query UsersWithHistory($serverId: ID, $userId: ID) { + servers(filter: {id: $serverId}) { + userCount + users(filter: {id: $userId}) { + id history { id diff --git a/kdb-web/src/app/modules/shared/components/history-btn/history-btn.component.ts b/kdb-web/src/app/modules/shared/components/history-btn/history-btn.component.ts index db89ea41..39c4cd45 100644 --- a/kdb-web/src/app/modules/shared/components/history-btn/history-btn.component.ts +++ b/kdb-web/src/app/modules/shared/components/history-btn/history-btn.component.ts @@ -1,5 +1,16 @@ import { Component, Input, OnInit } from "@angular/core"; import { History } from "../../../../models/data/data.model"; +import { UserListQuery } from "../../../../models/graphql/query.model"; +import { Server } from "../../../../models/data/server.model"; +import { DataService } from "../../../../services/data/data.service"; +import { AuthService } from "../../../../services/auth/auth.service"; +import { SpinnerService } from "../../../../services/spinner/spinner.service"; +import { ToastService } from "../../../../services/toast/toast.service"; +import { ConfirmationDialogService } from "../../../../services/confirmation-dialog/confirmation-dialog.service"; +import { FormBuilder } from "@angular/forms"; +import { TranslateService } from "@ngx-translate/core"; +import { ActivatedRoute } from "@angular/router"; +import { SidebarService } from "../../../../services/sidebar/sidebar.service"; @Component({ selector: "app-history-btn", @@ -8,19 +19,46 @@ import { History } from "../../../../models/data/data.model"; }) export class HistoryBtnComponent implements OnInit { - @Input() history: History[] = []; + @Input() id: number = 0; + @Input() query: string = ""; @Input() translationKey: string = ""; - public showSidebar: boolean = false; + public history: History[] = []; - public constructor() { + public showSidebar: boolean = false; + private server: Server = {}; + + public constructor( + private authService: AuthService, + private spinner: SpinnerService, + private toastService: ToastService, + private confirmDialog: ConfirmationDialogService, + private fb: FormBuilder, + private translate: TranslateService, + private data: DataService, + private route: ActivatedRoute, + private sidebar: SidebarService + ) { } public ngOnInit(): void { + this.server = this.sidebar.server$.value ?? {}; } public openHistory(): void { this.showSidebar = true; + this.data.query(this.query, { + serverId: this.server.id, userId: this.id + }, + (x: { servers: Server[] }) => { + return x.servers[0]; + } + ).subscribe(data => { + this.history = data.users[0].history ?? []; + this.spinner.hideSpinner(); + }); + + let oldHistory: Partial = {}; for (const history of this.history) { const attributes = Object.keys(history).map((key) => { diff --git a/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles-rules/auto-roles-rules.component.html b/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles-rules/auto-roles-rules.component.html index 3c389ab5..64154ee2 100644 --- a/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles-rules/auto-roles-rules.component.html +++ b/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles-rules/auto-roles-rules.component.html @@ -160,7 +160,7 @@
- + diff --git a/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles/auto-roles.component.html b/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles/auto-roles.component.html index a2677dc0..330b2016 100644 --- a/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles/auto-roles.component.html +++ b/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles/auto-roles.component.html @@ -193,7 +193,7 @@
- + diff --git a/kdb-web/src/app/modules/view/server/levels/components/levels/levels.component.html b/kdb-web/src/app/modules/view/server/levels/components/levels/levels.component.html index 97be32d8..4cb1859a 100644 --- a/kdb-web/src/app/modules/view/server/levels/components/levels/levels.component.html +++ b/kdb-web/src/app/modules/view/server/levels/components/levels/levels.component.html @@ -184,7 +184,7 @@
- + diff --git a/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles-rules/auto-roles-rules.component.ts b/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles-rules/auto-roles-rules.component.ts index 7f302851..5fab0523 100644 --- a/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles-rules/auto-roles-rules.component.ts +++ b/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles-rules/auto-roles-rules.component.ts @@ -1,4 +1,4 @@ -import { Component, OnDestroy, OnInit } from "@angular/core"; +import { Component, OnDestroy, OnInit, Query } from "@angular/core"; import { DataService } from "../../../../../../services/data/data.service"; import { ActivatedRoute, Router } from "@angular/router"; import { AutoRoleRule, AutoRoleRuleFilter } from "../../../../../../models/data/auto_role.model"; @@ -66,6 +66,8 @@ export class AutoRolesRulesComponent implements OnInit, OnDestroy { private unsubscriber = new Subject(); private server: Server = {}; + query: string = Queries.autoRoleRulesHistoryQuery; + constructor( private authService: AuthService, private spinner: SpinnerService, diff --git a/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles/auto-roles.component.html b/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles/auto-roles.component.html index 330b2016..b30ff372 100644 --- a/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles/auto-roles.component.html +++ b/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles/auto-roles.component.html @@ -126,7 +126,8 @@ - + {{autoRole.channelId}} @@ -191,9 +192,9 @@
- - - + + + diff --git a/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles/auto-roles.component.ts b/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles/auto-roles.component.ts index 12b070c0..77f249ad 100644 --- a/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles/auto-roles.component.ts +++ b/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles/auto-roles.component.ts @@ -63,6 +63,8 @@ export class AutoRolesComponent implements OnInit, OnDestroy { private unsubscriber = new Subject(); private server: Server = {}; + query: string = Queries.autoRolesWithHistoryQuery; + constructor( private authService: AuthService, private spinner: SpinnerService, -- 2.45.2 From 2b866b5ab1fc6266840d74c2af578d7c6cd5270d Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Fri, 14 Apr 2023 22:01:06 +0200 Subject: [PATCH 7/9] Improved level data loading #300 --- .../src/app/models/graphql/queries.model.ts | 21 ++++++++++--------- .../components/levels/levels.component.html | 2 +- .../components/levels/levels.component.ts | 2 ++ 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/kdb-web/src/app/models/graphql/queries.model.ts b/kdb-web/src/app/models/graphql/queries.model.ts index a8c0fd97..f3d68257 100644 --- a/kdb-web/src/app/models/graphql/queries.model.ts +++ b/kdb-web/src/app/models/graphql/queries.model.ts @@ -62,6 +62,17 @@ export class Queries { } createdAt modifiedAt + } + } + } + `; + + static levelWithHistoryQuery = ` + query LevelHistory($serverId: ID, $id: ID) { + servers(filter: {id: $serverId}) { + levelCount + levels(filter: {id: $id}) { + id history { id @@ -233,16 +244,6 @@ export class Queries { createdAt modifiedAt - - history { - id - emojiName - roleId - autoRole - deleted - dateFrom - dateTo - } } } } diff --git a/kdb-web/src/app/modules/view/server/levels/components/levels/levels.component.html b/kdb-web/src/app/modules/view/server/levels/components/levels/levels.component.html index 4cb1859a..0c8b1945 100644 --- a/kdb-web/src/app/modules/view/server/levels/components/levels/levels.component.html +++ b/kdb-web/src/app/modules/view/server/levels/components/levels/levels.component.html @@ -184,7 +184,7 @@
- +