From e283a18def3f2d5e4a81280b47bf8505747d460b Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Wed, 16 Aug 2023 20:55:42 +0200 Subject: [PATCH 1/5] Added logic to check server view permissions #339 #1.1.0.rc3 --- kdb-web/package.json | 2 +- kdb-web/src/app/models/auth/auth-user.dto.ts | 6 +++ .../modules/shared/guards/auth/auth.guard.ts | 45 ++++++++++++++----- .../view/server/server-routing.module.ts | 17 ++++--- kdb-web/src/assets/version.json | 2 +- 5 files changed, 55 insertions(+), 17 deletions(-) diff --git a/kdb-web/package.json b/kdb-web/package.json index 6e63ff9b..aca808cd 100644 --- a/kdb-web/package.json +++ b/kdb-web/package.json @@ -1,6 +1,6 @@ { "name": "kdb-web", - "version": "1.1.0.rc2", + "version": "1.1.0.rc3", "scripts": { "ng": "ng", "update-version": "ts-node-esm update-version.ts", diff --git a/kdb-web/src/app/models/auth/auth-user.dto.ts b/kdb-web/src/app/models/auth/auth-user.dto.ts index 4b1e90e4..50b913e0 100644 --- a/kdb-web/src/app/models/auth/auth-user.dto.ts +++ b/kdb-web/src/app/models/auth/auth-user.dto.ts @@ -25,3 +25,9 @@ export interface UserDTO { isAdmin: boolean; isModerator: boolean; } + +export enum MemberRoles { + Moderator = 0, + Admin = 1, + Technician = 2, +} diff --git a/kdb-web/src/app/modules/shared/guards/auth/auth.guard.ts b/kdb-web/src/app/modules/shared/guards/auth/auth.guard.ts index 4711dad9..c3608a54 100644 --- a/kdb-web/src/app/modules/shared/guards/auth/auth.guard.ts +++ b/kdb-web/src/app/modules/shared/guards/auth/auth.guard.ts @@ -1,17 +1,20 @@ -import { Injectable } from '@angular/core'; -import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot } from '@angular/router'; -import { catchError } from 'rxjs/operators'; -import { AuthService } from 'src/app/services/auth/auth.service'; -import { ThemeService } from 'src/app/services/theme/theme.service'; +import { Injectable } from "@angular/core"; +import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot } from "@angular/router"; +import { catchError } from "rxjs/operators"; +import { AuthService } from "src/app/services/auth/auth.service"; +import { ThemeService } from "src/app/services/theme/theme.service"; +import { SidebarService } from "../../../../services/sidebar/sidebar.service"; +import { MemberRoles } from "../../../../models/auth/auth-user.dto"; @Injectable({ - providedIn: 'root' + providedIn: "root" }) export class AuthGuard implements CanActivate { constructor( private router: Router, private authService: AuthService, - private themeService: ThemeService + private themeService: ThemeService, + private sidebarService: SidebarService ) { } @@ -26,19 +29,41 @@ export class AuthGuard implements CanActivate { return false; } - const role = route.data['role']; - if (role) { + const role = route.data["role"]; + const memberRole = route.data["memberRole"]; + if (role !== undefined) { this.authService.hasUserPermission(role).then(async hasPermission => { let authUser = await this.authService.getLoggedInUser(); let isTechnician = authUser?.users?.map(u => u.isTechnician).filter(u => u) ?? []; if (!hasPermission && !isTechnician) { - this.router.navigate(['/dashboard']); + this.router.navigate(["/dashboard"]); return false; } return true; }); } + + if (memberRole !== undefined) { + let userHasAccess = false; + let authUser = await this.authService.getLoggedInUser(); + authUser?.users?.forEach(u => { + if (u.server === +(this.sidebarService.server$.value?.id ?? 0)) { + if ( + memberRole === MemberRoles.Moderator && u.isModerator || + memberRole === MemberRoles.Admin && u.isAdmin || + memberRole === MemberRoles.Technician && u.isTechnician + ) { + userHasAccess = true; + } + } + }); + if (!userHasAccess) { + this.router.navigate(["/dashboard"]); + return false; + } + return true; + } return true; } } diff --git a/kdb-web/src/app/modules/view/server/server-routing.module.ts b/kdb-web/src/app/modules/view/server/server-routing.module.ts index c5626e9b..b0e09575 100644 --- a/kdb-web/src/app/modules/view/server/server-routing.module.ts +++ b/kdb-web/src/app/modules/view/server/server-routing.module.ts @@ -3,15 +3,22 @@ import { RouterModule, Routes } from "@angular/router"; import { ServerDashboardComponent } from "./server-dashboard/server-dashboard.component"; import { ProfileComponent } from "./profile/profile.component"; import { MembersComponent } from "./members/members.component"; +import { AuthGuard } from "../../shared/guards/auth/auth.guard"; +import { MemberRoles } from "../../../models/auth/auth-user.dto"; const routes: Routes = [ { path: "", component: ServerDashboardComponent }, - { path: "members", component: MembersComponent }, + { path: "members", component: MembersComponent, canActivate: [AuthGuard], data: { memberRole: MemberRoles.Moderator } }, { path: "members/:memberId", component: ProfileComponent }, - { path: "auto-roles", loadChildren: () => import("./auto-role/auto-role.module").then(m => m.AutoRoleModule) }, - { path: "levels", loadChildren: () => import("./levels/levels.module").then(m => m.LevelsModule) }, - { path: "achievements", loadChildren: () => import("./achievements/achievements.module").then(m => m.AchievementsModule) }, - { path: "config", loadChildren: () => import("./config/config.module").then(m => m.ConfigModule) } + { + path: "auto-roles", + loadChildren: () => import("./auto-role/auto-role.module").then(m => m.AutoRoleModule), + canActivate: [AuthGuard], + data: { memberRole: MemberRoles.Moderator } + }, + { path: "levels", loadChildren: () => import("./levels/levels.module").then(m => m.LevelsModule), canActivate: [AuthGuard], data: { memberRole: MemberRoles.Moderator } }, + { path: "achievements", loadChildren: () => import("./achievements/achievements.module").then(m => m.AchievementsModule), data: { memberRole: MemberRoles.Moderator } }, + { path: "config", loadChildren: () => import("./config/config.module").then(m => m.ConfigModule), data: { memberRole: MemberRoles.Admin } } ]; @NgModule({ diff --git a/kdb-web/src/assets/version.json b/kdb-web/src/assets/version.json index f4dc3d61..2e25f08e 100644 --- a/kdb-web/src/assets/version.json +++ b/kdb-web/src/assets/version.json @@ -2,6 +2,6 @@ "WebVersion": { "Major": "1", "Minor": "1", - "Micro": "0.rc2" + "Micro": "0.rc3" } } \ No newline at end of file -- 2.45.2 From aa2c80ec129f907e0b0019b1abbe9728baa135bf Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Wed, 16 Aug 2023 21:08:34 +0200 Subject: [PATCH 2/5] Added feature flag checks #338 #1.1.0.rc3 --- .../modules/boot_log/boot_log_on_ready_event.py | 8 ++++++++ kdb-bot/src/modules/level/level_seeder.py | 10 ++++++++++ .../events/permission_on_member_update_event.py | 14 +++++++++++++- .../permission/events/permission_on_ready_event.py | 11 +++++++++-- 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/kdb-bot/src/modules/boot_log/boot_log_on_ready_event.py b/kdb-bot/src/modules/boot_log/boot_log_on_ready_event.py index fd42102f..1e2e5a52 100644 --- a/kdb-bot/src/modules/boot_log/boot_log_on_ready_event.py +++ b/kdb-bot/src/modules/boot_log/boot_log_on_ready_event.py @@ -11,6 +11,7 @@ from bot_core.abc.message_service_abc import MessageServiceABC from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings from bot_data.model.server_config import ServerConfig +from bot_data.model.technician_config import TechnicianConfig class BootLogOnReadyEvent(OnReadyABC): @@ -21,6 +22,7 @@ class BootLogOnReadyEvent(OnReadyABC): bot: DiscordBotServiceABC, message_service: MessageServiceABC, translate: TranslatePipe, + tech_config: TechnicianConfig, ): OnReadyABC.__init__(self) self._config = config @@ -29,11 +31,17 @@ class BootLogOnReadyEvent(OnReadyABC): self._bot = bot self._message_service = message_service self._t = translate + self._tech_config = tech_config self._logger.info(__name__, f"Module {type(self)} loaded") async def on_ready(self): self._logger.debug(__name__, f"Module {type(self)} started") + if not FeatureFlagsSettings.get_flag_from_dict( + self._tech_config.feature_flags, FeatureFlagsEnum.boot_log_module + ): + return + try: start_time = self._config.get_configuration("Bot_StartTime") init_time = round( diff --git a/kdb-bot/src/modules/level/level_seeder.py b/kdb-bot/src/modules/level/level_seeder.py index 1ed5ab7d..19c7b773 100644 --- a/kdb-bot/src/modules/level/level_seeder.py +++ b/kdb-bot/src/modules/level/level_seeder.py @@ -1,14 +1,18 @@ import discord +from cpl_core.configuration import ConfigurationABC from cpl_core.database.context import DatabaseContextABC from cpl_discord.container import Guild from cpl_discord.service import DiscordBotServiceABC from discord import Permissions, Colour +from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum +from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings from bot_core.logging.database_logger import DatabaseLogger from bot_data.abc.data_seeder_abc import DataSeederABC from bot_data.abc.server_repository_abc import ServerRepositoryABC from bot_data.model.level import Level from bot_data.model.server import Server +from bot_data.model.server_config import ServerConfig from bot_data.service.level_repository_service import LevelRepositoryService from modules.level.configuration.default_level_settings import DefaultLevelSettings from modules.level.service.level_service import LevelService @@ -17,6 +21,7 @@ from modules.level.service.level_service import LevelService class LevelSeeder(DataSeederABC): def __init__( self, + config: ConfigurationABC, logger: DatabaseLogger, levels: DefaultLevelSettings, level_repo: LevelRepositoryService, @@ -27,6 +32,7 @@ class LevelSeeder(DataSeederABC): ): DataSeederABC.__init__(self) + self._config = config self._logger = logger self._levels = level_repo self._servers = servers @@ -65,6 +71,10 @@ class LevelSeeder(DataSeederABC): async def seed(self): # create levels for guild in self._bot.guilds: + server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{guild.id}") + if not FeatureFlagsSettings.get_flag_from_dict(server_config.feature_flags, FeatureFlagsEnum.level_module): + continue + created_default = False if guild.roles.where(lambda r: r.name == self._level_header).first_or_default() is None: await guild.create_role(name=self._level_header) diff --git a/kdb-bot/src/modules/permission/events/permission_on_member_update_event.py b/kdb-bot/src/modules/permission/events/permission_on_member_update_event.py index 30d567ee..b2e65c19 100644 --- a/kdb-bot/src/modules/permission/events/permission_on_member_update_event.py +++ b/kdb-bot/src/modules/permission/events/permission_on_member_update_event.py @@ -1,17 +1,29 @@ import discord +from cpl_core.configuration import ConfigurationABC from cpl_core.logging import LoggerABC from cpl_discord.events import OnMemberUpdateABC +from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum +from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings +from bot_data.model.server_config import ServerConfig from modules.permission.abc.permission_service_abc import PermissionServiceABC class PermissionOnMemberUpdateEvent(OnMemberUpdateABC): - def __init__(self, logger: LoggerABC, permission_service: PermissionServiceABC): + def __init__(self, config: ConfigurationABC, logger: LoggerABC, permission_service: PermissionServiceABC): OnMemberUpdateABC.__init__(self) + self._config = config self._logger = logger self._permission_service = permission_service async def on_member_update(self, before: discord.Member, after: discord.Member): + if before.guild is not None: + server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{before.guild.id}") + if not FeatureFlagsSettings.get_flag_from_dict( + server_config.feature_flags, FeatureFlagsEnum.permission_module + ): + return + self._logger.debug(__name__, f"Module {type(self)} started") if before.roles != after.roles: diff --git a/kdb-bot/src/modules/permission/events/permission_on_ready_event.py b/kdb-bot/src/modules/permission/events/permission_on_ready_event.py index 4da13dc0..a6dbd62c 100644 --- a/kdb-bot/src/modules/permission/events/permission_on_ready_event.py +++ b/kdb-bot/src/modules/permission/events/permission_on_ready_event.py @@ -1,15 +1,22 @@ from cpl_core.logging import LoggerABC from cpl_discord.events import OnReadyABC +from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum +from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings +from bot_data.model.technician_config import TechnicianConfig from modules.permission.abc.permission_service_abc import PermissionServiceABC class PermissionOnReadyEvent(OnReadyABC): - def __init__(self, logger: LoggerABC, permission_service: PermissionServiceABC): + def __init__(self, logger: LoggerABC, permission_service: PermissionServiceABC, tech_config: TechnicianConfig): OnReadyABC.__init__(self) self._logger = logger self._permission_service = permission_service + self._tech_config = tech_config async def on_ready(self): - self._logger.debug(__name__, f"Module {type(self)} started") + if not FeatureFlagsSettings.get_flag_from_dict( + self._tech_config.feature_flags, FeatureFlagsEnum.permission_module + ): + return self._permission_service.on_ready() -- 2.45.2 From 4cea31fce54303a2a49a6a121d8d9c442de10267 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Wed, 16 Aug 2023 21:20:14 +0200 Subject: [PATCH 3/5] Added achievement validation triggers #340 #1.1.0.rc3 --- .../achievements/achievements_module.py | 6 ++ .../achievement_on_reaction_add_event.py | 61 +++++++++++++++++++ .../achievement_on_reaction_remove_event.py | 61 +++++++++++++++++++ ...achievement_on_voice_state_update_event.py | 55 +++++++++++++++++ 4 files changed, 183 insertions(+) create mode 100644 kdb-bot/src/modules/achievements/events/achievement_on_reaction_add_event.py create mode 100644 kdb-bot/src/modules/achievements/events/achievement_on_reaction_remove_event.py create mode 100644 kdb-bot/src/modules/achievements/events/achievement_on_voice_state_update_event.py diff --git a/kdb-bot/src/modules/achievements/achievements_module.py b/kdb-bot/src/modules/achievements/achievements_module.py index cfe1ce2b..3860feac 100644 --- a/kdb-bot/src/modules/achievements/achievements_module.py +++ b/kdb-bot/src/modules/achievements/achievements_module.py @@ -10,6 +10,9 @@ from modules.achievements.achievement_attribute_resolver import AchievementAttri from modules.achievements.achievement_service import AchievementService from modules.achievements.commands.achievements_group import AchievementGroup from modules.achievements.events.achievement_on_message_event import AchievementOnMessageEvent +from modules.achievements.events.achievement_on_reaction_add_event import AchievementOnReactionAddEvent +from modules.achievements.events.achievement_on_reaction_remove_event import AchievementOnReactionRemoveEvent +from modules.achievements.events.achievement_on_voice_state_update_event import AchievementOnVoiceStateUpdateEvent class AchievementsModule(ModuleABC): @@ -26,3 +29,6 @@ class AchievementsModule(ModuleABC): self._dc.add_command(AchievementGroup) self._dc.add_event(DiscordEventTypesEnum.on_message.value, AchievementOnMessageEvent) + self._dc.add_event(DiscordEventTypesEnum.on_reaction_add.value, AchievementOnReactionAddEvent) + self._dc.add_event(DiscordEventTypesEnum.on_reaction_remove.value, AchievementOnReactionRemoveEvent) + self._dc.add_event(DiscordEventTypesEnum.on_voice_state_update.value, AchievementOnVoiceStateUpdateEvent) diff --git a/kdb-bot/src/modules/achievements/events/achievement_on_reaction_add_event.py b/kdb-bot/src/modules/achievements/events/achievement_on_reaction_add_event.py new file mode 100644 index 00000000..f489bb08 --- /dev/null +++ b/kdb-bot/src/modules/achievements/events/achievement_on_reaction_add_event.py @@ -0,0 +1,61 @@ +from typing import Union + +import discord +from cpl_core.configuration import ConfigurationABC +from cpl_core.database.context import DatabaseContextABC +from cpl_core.logging import LoggerABC +from cpl_discord.events import OnReactionAddABC +from cpl_discord.service import DiscordBotServiceABC + +from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum +from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings +from bot_data.abc.server_repository_abc import ServerRepositoryABC +from bot_data.abc.user_repository_abc import UserRepositoryABC +from bot_data.model.server_config import ServerConfig +from modules.achievements.achievement_service import AchievementService + + +class AchievementOnReactionAddEvent(OnReactionAddABC): + def __init__( + self, + config: ConfigurationABC, + logger: LoggerABC, + bot: DiscordBotServiceABC, + achievements: AchievementService, + db: DatabaseContextABC, + servers: ServerRepositoryABC, + users: UserRepositoryABC, + ): + OnReactionAddABC.__init__(self) + + self._config = config + self._logger = logger + self._bot = bot + self._achievements = achievements + self._db = db + self._servers = servers + self._users = users + + async def on_reaction_add(self, reaction: discord.reaction.Reaction, user: Union[discord.Member, discord.User]): + if not isinstance(user, discord.Member): + return + + if user.guild is None: + return + + if user.bot: + return + + server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{user.guild.id}") + if not FeatureFlagsSettings.get_flag_from_dict( + server_config.feature_flags, FeatureFlagsEnum.achievements_module + ): + return + + server = self._servers.get_server_by_discord_id(user.guild.id) + user = self._users.get_user_by_discord_id_and_server_id(user.author.id, server.id) + + user.reaction_count += 1 + self._db.save_changes() + + await self._achievements.validate_achievements_for_user(user) diff --git a/kdb-bot/src/modules/achievements/events/achievement_on_reaction_remove_event.py b/kdb-bot/src/modules/achievements/events/achievement_on_reaction_remove_event.py new file mode 100644 index 00000000..4efb5588 --- /dev/null +++ b/kdb-bot/src/modules/achievements/events/achievement_on_reaction_remove_event.py @@ -0,0 +1,61 @@ +from typing import Union + +import discord +from cpl_core.configuration import ConfigurationABC +from cpl_core.database.context import DatabaseContextABC +from cpl_core.logging import LoggerABC +from cpl_discord.events import OnReactionRemoveABC +from cpl_discord.service import DiscordBotServiceABC + +from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum +from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings +from bot_data.abc.server_repository_abc import ServerRepositoryABC +from bot_data.abc.user_repository_abc import UserRepositoryABC +from bot_data.model.server_config import ServerConfig +from modules.achievements.achievement_service import AchievementService + + +class AchievementOnReactionRemoveEvent(OnReactionRemoveABC): + def __init__( + self, + config: ConfigurationABC, + logger: LoggerABC, + bot: DiscordBotServiceABC, + achievements: AchievementService, + db: DatabaseContextABC, + servers: ServerRepositoryABC, + users: UserRepositoryABC, + ): + OnReactionRemoveABC.__init__(self) + + self._config = config + self._logger = logger + self._bot = bot + self._achievements = achievements + self._db = db + self._servers = servers + self._users = users + + async def on_reaction_remove(self, reaction: discord.reaction.Reaction, user: Union[discord.Member, discord.User]): + if not isinstance(user, discord.Member): + return + + if user.guild is None: + return + + if user.bot: + return + + server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{user.guild.id}") + if not FeatureFlagsSettings.get_flag_from_dict( + server_config.feature_flags, FeatureFlagsEnum.achievements_module + ): + return + + server = self._servers.get_server_by_discord_id(user.guild.id) + user = self._users.get_user_by_discord_id_and_server_id(user.author.id, server.id) + + user.reaction_count -= 1 + self._db.save_changes() + + await self._achievements.validate_achievements_for_user(user) diff --git a/kdb-bot/src/modules/achievements/events/achievement_on_voice_state_update_event.py b/kdb-bot/src/modules/achievements/events/achievement_on_voice_state_update_event.py new file mode 100644 index 00000000..307d4e18 --- /dev/null +++ b/kdb-bot/src/modules/achievements/events/achievement_on_voice_state_update_event.py @@ -0,0 +1,55 @@ +import discord +from cpl_core.configuration import ConfigurationABC +from cpl_core.database.context import DatabaseContextABC +from cpl_core.logging import LoggerABC +from cpl_discord.events import OnVoiceStateUpdateABC +from cpl_discord.service import DiscordBotServiceABC + +from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum +from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings +from bot_data.abc.server_repository_abc import ServerRepositoryABC +from bot_data.abc.user_repository_abc import UserRepositoryABC +from bot_data.model.server_config import ServerConfig +from modules.achievements.achievement_service import AchievementService + + +class AchievementOnVoiceStateUpdateEvent(OnVoiceStateUpdateABC): + def __init__( + self, + config: ConfigurationABC, + logger: LoggerABC, + bot: DiscordBotServiceABC, + achievements: AchievementService, + db: DatabaseContextABC, + servers: ServerRepositoryABC, + users: UserRepositoryABC, + ): + OnVoiceStateUpdateABC.__init__(self) + + self._config = config + self._logger = logger + self._bot = bot + self._achievements = achievements + self._db = db + self._servers = servers + self._users = users + + async def on_voice_state_update( + self, member: discord.member.Member, before: discord.member.VoiceState, after: discord.member.VoiceState + ): + if member.guild is None: + return + + if member.author.bot: + return + + server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{member.guild.id}") + if not FeatureFlagsSettings.get_flag_from_dict( + server_config.feature_flags, FeatureFlagsEnum.achievements_module + ): + return + + server = self._servers.get_server_by_discord_id(member.guild.id) + user = self._users.get_user_by_discord_id_and_server_id(member.author.id, server.id) + + await self._achievements.validate_achievements_for_user(user) -- 2.45.2 From fe3d67eff56dca46ddec7f2b791aabbf148c7c60 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Wed, 16 Aug 2023 21:23:03 +0200 Subject: [PATCH 4/5] Fixed client data #337 #1.1.0.rc3 --- kdb-bot/src/bot_graphql/queries/client_query.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kdb-bot/src/bot_graphql/queries/client_query.py b/kdb-bot/src/bot_graphql/queries/client_query.py index e5cd4c68..6e69a369 100644 --- a/kdb-bot/src/bot_graphql/queries/client_query.py +++ b/kdb-bot/src/bot_graphql/queries/client_query.py @@ -40,7 +40,7 @@ class ClientQuery(DataQueryWithHistoryABC): @staticmethod def resolve_received_message_count(client: Client, *_): - return client.received_command_count + return client.received_message_count @staticmethod def resolve_deleted_message_count(client: Client, *_): -- 2.45.2 From 2d5ce58612e1cbe93da4d2cda82dca1610a4593c Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Wed, 16 Aug 2023 22:12:40 +0200 Subject: [PATCH 5/5] Fixed complaint command #341 #1.1.0.rc3 --- kdb-bot/src/bot/bot.json | 3 ++- .../mutations/server_config_mutation.py | 6 +++--- kdb-bot/src/modules/base/command/submit_group.py | 15 +++++++-------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/kdb-bot/src/bot/bot.json b/kdb-bot/src/bot/bot.json index 4ba86b24..949b297b 100644 --- a/kdb-bot/src/bot/bot.json +++ b/kdb-bot/src/bot/bot.json @@ -30,7 +30,8 @@ "requests-oauthlib==1.3.1", "icmplib==3.0.3", "ariadne==0.20.1", - "cryptography==41.0.2" + "cryptography==41.0.2", + "discord>=2.3.2" ], "DevDependencies": [ "cpl-cli==2023.4.0.post3", diff --git a/kdb-bot/src/bot_graphql/mutations/server_config_mutation.py b/kdb-bot/src/bot_graphql/mutations/server_config_mutation.py index 0968b2d4..4a56d9f0 100644 --- a/kdb-bot/src/bot_graphql/mutations/server_config_mutation.py +++ b/kdb-bot/src/bot_graphql/mutations/server_config_mutation.py @@ -43,7 +43,7 @@ class ServerConfigMutation(QueryABC): if "id" not in input: raise ValueError("Id not set") - server_config = self._server_configs.get_server_config_by_server(input["id"]) + server_config = self._server_configs.get_server_config_by_id(int(input["id"])) self._can_user_mutate_data(Route.get_user().users[0].server, UserRoleEnum.technician) server_config.message_delete_timer = ( @@ -137,7 +137,7 @@ class ServerConfigMutation(QueryABC): return server_config def _update_afk_channel_ids(self, new_config: ServerConfig): - old_config = self._server_configs.get_server_config_by_id(new_config.server.id) + old_config = self._server_configs.get_server_config_by_server(new_config.server.id) for channel_id in old_config.afk_channel_ids: if channel_id in new_config.afk_channel_ids: continue @@ -155,7 +155,7 @@ class ServerConfigMutation(QueryABC): ) def _update_team_role_ids(self, new_config: ServerConfig): - old_config = self._server_configs.get_server_config_by_id(new_config.server.id) + old_config = self._server_configs.get_server_config_by_server(new_config.server.id) for role_id in old_config.team_role_ids: if role_id.role_id in new_config.team_role_ids.select(lambda x: int(x.role_id)): continue diff --git a/kdb-bot/src/modules/base/command/submit_group.py b/kdb-bot/src/modules/base/command/submit_group.py index 56812e14..ad1570e3 100644 --- a/kdb-bot/src/modules/base/command/submit_group.py +++ b/kdb-bot/src/modules/base/command/submit_group.py @@ -1,3 +1,4 @@ +from cpl_core.dependency_injection import ServiceProviderABC from cpl_core.logging import LoggerABC from cpl_discord.command import DiscordCommandABC from cpl_discord.service import DiscordBotServiceABC @@ -10,15 +11,12 @@ from modules.base.forms.complaint_form import ComplaintForm class SubmitGroup(DiscordCommandABC): - def __init__( - self, logger: LoggerABC, bot: DiscordBotServiceABC, complaint_form: ComplaintForm, bug_form: BugReportForm - ): + def __init__(self, services: ServiceProviderABC, logger: LoggerABC, bot: DiscordBotServiceABC): DiscordCommandABC.__init__(self) + self._services = services self._logger = logger self._bot = bot - self._complaint_form = complaint_form - self._bug_form = bug_form @commands.hybrid_group() @commands.guild_only() @@ -30,14 +28,15 @@ class SubmitGroup(DiscordCommandABC): @CommandChecks.check_is_ready() async def complaint(self, ctx: Context): self._logger.debug(__name__, f"Received command complaint {ctx}") - await ctx.interaction.response.send_modal(self._complaint_form) + complaint_form: ComplaintForm = self._services.get_service(ComplaintForm) + await ctx.interaction.response.send_modal(complaint_form) self._logger.trace(__name__, f"Finished command complaint {ctx}") - pass @submit.command() @commands.guild_only() @CommandChecks.check_is_ready() async def bug_report(self, ctx: Context): self._logger.debug(__name__, f"Received command complaint {ctx}") - await ctx.interaction.response.send_modal(self._bug_form) + bug_form: BugReportForm = self._services.get_service(BugReportForm) + await ctx.interaction.response.send_modal(bug_form) self._logger.trace(__name__, f"Finished command complaint {ctx}") -- 2.45.2