diff --git a/kdb-bot/src/bot/bot.json b/kdb-bot/src/bot/bot.json index d7d6a2d7..66f56772 100644 --- a/kdb-bot/src/bot/bot.json +++ b/kdb-bot/src/bot/bot.json @@ -32,7 +32,8 @@ "cpl-discord==2022.12.2" ], "DevDependencies": [ - "cpl-cli==2022.12.1.post3" + "cpl-cli==2022.12.1.post3", + "pygount==1.5.1" ], "PythonVersion": ">=3.10.4", "PythonPath": {}, diff --git a/kdb-bot/src/bot/config b/kdb-bot/src/bot/config index e3019156..79861447 160000 --- a/kdb-bot/src/bot/config +++ b/kdb-bot/src/bot/config @@ -1 +1 @@ -Subproject commit e3019156c058a93c092932dad75db39576bc55a7 +Subproject commit 7986144705052ff38472a5d3f0776cb6c1752a55 diff --git a/kdb-bot/src/bot_api/config b/kdb-bot/src/bot_api/config index 81021418..c712f856 160000 --- a/kdb-bot/src/bot_api/config +++ b/kdb-bot/src/bot_api/config @@ -1 +1 @@ -Subproject commit 81021418c21d45cee54478ab5fd69f9ce7261644 +Subproject commit c712f856ebe30c71ac0b144045599ed2f91a1cba diff --git a/kdb-bot/src/bot_graphql/query.py b/kdb-bot/src/bot_graphql/query.py index f8e7853a..8133e4dc 100644 --- a/kdb-bot/src/bot_graphql/query.py +++ b/kdb-bot/src/bot_graphql/query.py @@ -63,7 +63,7 @@ class Query(QueryABC): self.set_field("guilds", self._resolve_guilds) def _resolve_guilds(self, *_, filter=None): - if filter is None and "id" not in filter: + if filter is None or "id" not in filter: return self._bot.guilds return self._bot.guilds.where(lambda g: g.id == int(filter["id"])) diff --git a/kdb-web/src/app/models/graphql/mutations.model.ts b/kdb-web/src/app/models/graphql/mutations.model.ts index f7be1c11..db06c8f8 100644 --- a/kdb-web/src/app/models/graphql/mutations.model.ts +++ b/kdb-web/src/app/models/graphql/mutations.model.ts @@ -14,4 +14,30 @@ export class Mutations { } } `; + + static createAutoRole = ` + mutation updateAutoRole($serverId: ID, $channelId: String, $messageId: String) { + autoRole { + createAutoRole(input: { serverId: $serverId, channelId: $channelId, messageId: $messageId }) { + id + channelId + channelName + messageId + } + } + } + `; + + static deleteAutoRole = ` + mutation updateAutoRole($id: ID) { + autoRole { + deleteAutoRole(id: $id) { + id + channelId + channelName + messageId + } + } + } + `; } diff --git a/kdb-web/src/app/models/graphql/queries.model.ts b/kdb-web/src/app/models/graphql/queries.model.ts index bd93162b..c71733eb 100644 --- a/kdb-web/src/app/models/graphql/queries.model.ts +++ b/kdb-web/src/app/models/graphql/queries.model.ts @@ -166,6 +166,10 @@ export class Queries { messageId autoRoleRuleCount + server { + id + } + createdAt modifiedAt } diff --git a/kdb-web/src/app/models/graphql/query.model.ts b/kdb-web/src/app/models/graphql/query.model.ts index 904cbf41..a6c1090f 100644 --- a/kdb-web/src/app/models/graphql/query.model.ts +++ b/kdb-web/src/app/models/graphql/query.model.ts @@ -2,6 +2,7 @@ import { Server } from "../data/server.model"; import { User } from "../data/user.model"; import { AutoRole } from "../data/auto_role.model"; import { Guild } from "../data/discord.model"; +import { Level } from "../data/level.model"; export interface Query { serverCount: number; @@ -19,7 +20,7 @@ export interface UserListQuery { export interface LevelListQuery { levelCount: number; - levels: User[]; + levels: Level[]; } export interface AutoRoleQuery { diff --git a/kdb-web/src/app/models/graphql/result.model.ts b/kdb-web/src/app/models/graphql/result.model.ts index bc28521d..8198fda2 100644 --- a/kdb-web/src/app/models/graphql/result.model.ts +++ b/kdb-web/src/app/models/graphql/result.model.ts @@ -1,4 +1,10 @@ import { User } from "../data/user.model"; +import { AutoRole } from "../data/auto_role.model"; + +export interface GraphQLResult { + data: any; + errors?: []; +} export interface QueryResult { data: any; @@ -9,3 +15,10 @@ export interface UpdateUserMutationResult { updateUser: User }; } +export interface AutoRoleMutationResult { + autoRole: { + createAutoRole?: AutoRole + updateAutoRole?: AutoRole + deleteAutoRole?: AutoRole + }; +} diff --git a/kdb-web/src/app/modules/shared/shared.module.ts b/kdb-web/src/app/modules/shared/shared.module.ts index bf719ea6..1402c6ef 100644 --- a/kdb-web/src/app/modules/shared/shared.module.ts +++ b/kdb-web/src/app/modules/shared/shared.module.ts @@ -20,6 +20,7 @@ import { IpAddressPipe } from './pipes/ip-address.pipe'; import { BoolPipe } from './pipes/bool.pipe'; import { PanelMenuModule } from 'primeng/panelmenu'; import { PanelModule } from "primeng/panel"; +import { InputNumberModule } from 'primeng/inputnumber'; @@ -49,6 +50,7 @@ import { PanelModule } from "primeng/panel"; DynamicDialogModule, PanelMenuModule, PanelModule, + InputNumberModule, ], exports: [ ButtonModule, @@ -72,6 +74,7 @@ import { PanelModule } from "primeng/panel"; AuthRolePipe, IpAddressPipe, BoolPipe, + InputNumberModule, ] }) export class SharedModule { } 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 2440f09d..538afde3 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,10 +1,22 @@ -import { Component } from '@angular/core'; +import { Component, OnInit } from "@angular/core"; +import { DataService } from "../../../../../../services/data/data.service"; +import { ActivatedRoute } from "@angular/router"; @Component({ - selector: 'app-auto-roles-rules', - templateUrl: './auto-roles-rules.component.html', - styleUrls: ['./auto-roles-rules.component.scss'] + selector: "app-auto-roles-rules", + templateUrl: "./auto-roles-rules.component.html", + styleUrls: ["./auto-roles-rules.component.scss"] }) -export class AutoRolesRulesComponent { +export class AutoRolesRulesComponent implements OnInit { + + constructor( + private data: DataService, + private route: ActivatedRoute, + ) { + } + + ngOnInit(): void { + this.data.getServerFromRoute(this.route); + } } 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 dc5bd7a8..16cb0710 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 @@ -18,7 +18,7 @@
- + + + + + icon="pi pi-times-circle" (click)="onRowEditCancel(ri)">
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 844a9c04..6659fc68 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 @@ -16,7 +16,7 @@ import { AutoRoleQuery, SingleDiscordQuery } from "../../../../../../models/grap import { Queries } from "../../../../../../models/graphql/queries.model"; import { catchError, debounceTime } from "rxjs/operators"; import { Table } from "primeng/table"; -import { UpdateUserMutationResult } from "../../../../../../models/graphql/result.model"; +import { AutoRoleMutationResult } from "../../../../../../models/graphql/result.model"; import { Mutations } from "../../../../../../models/graphql/mutations.model"; import { throwError } from "rxjs"; import { AutoRole, AutoRoleFilter } from "../../../../../../models/data/auto_role.model"; @@ -87,7 +87,9 @@ export class AutoRolesComponent implements OnInit { this.guild = data.guilds[0]; this.channels = this.guild.channels .filter(x => x.type === ChannelType.text) - .map(x => {return {value: x.name, label: x.id}}); + .map(x => { + return { label: x.name, value: x }; + }); this.spinner.hideSpinner(); }); @@ -167,48 +169,39 @@ export class AutoRolesComponent implements OnInit { this.filterForm.reset(); } - onRowEditInit(table: Table, user: User, index: number) { - this.clonedUsers[index] = { ...user }; + onRowEditInit(table: Table, autoRole: AutoRole, index: number) { + this.clonedUsers[index] = { ...autoRole }; } - onRowEditSave(table: Table, newUser: User, index: number) { - // const oldUser = this.clonedUsers[index]; - // delete this.clonedUsers[index]; - - // if (JSON.stringify(oldUser) === JSON.stringify(newUser) && !this.isEditingNew) { - // console.log(1, oldUser, newUser, JSON.stringify(oldUser) === JSON.stringify(newUser), !this.isEditingNew); - // return; - // } - - if (this.isEditingNew && JSON.stringify(newUser) === JSON.stringify(this.newAutoRoleTemplate)) { + onRowEditSave(table: Table, newAutoRole: AutoRole, index: number) { + if (this.isEditingNew && JSON.stringify(newAutoRole) === JSON.stringify(this.newAutoRoleTemplate)) { this.isEditingNew = false; this.auto_roles.splice(index, 1); return; } - if (!newUser.id || !newUser.xp && !newUser.level?.id) { + if (!newAutoRole.id || !newAutoRole.channelId && !newAutoRole.messageId) { return; } this.spinner.showSpinner(); - this.data.mutation(Mutations.updateUser, { - id: newUser.id, - xp: newUser.xp, - levelId: newUser.level?.id + this.data.mutation(Mutations.createAutoRole, { + serverId: this.sidebar.server$.value?.id, + channelId: newAutoRole.channelId, + messageId: newAutoRole.messageId } ).pipe(catchError(err => { this.spinner.hideSpinner(); - this.toastService.error(this.translate.instant("view.server.members.message.user_change_failed"), this.translate.instant("view.server.members.message.user_change_failed_d", { name: newUser.name })); + this.toastService.error(this.translate.instant("view.server.auto_roles.message.auto_role_create_failed"), this.translate.instant("view.server.auto_roles.message.auto_role_create_failed_d")); return throwError(err); - })).subscribe(_ => { + })).subscribe(result => { this.spinner.hideSpinner(); - this.toastService.success(this.translate.instant("view.server.members.message.user_changed"), this.translate.instant("view.server.members.message.user_changed_d", { name: newUser.name })); + this.toastService.success(this.translate.instant("view.server.auto_roles.message.auto_role_created"), this.translate.instant("view.server.auto_roles.message.auto_role_create_d", { id: result.autoRole.createAutoRole?.id })); this.loadNextPage(); }); - } - onRowEditCancel(user: User, index: number) { + onRowEditCancel(index: number) { if (this.isEditingNew) { this.auto_roles.splice(index, 1); delete this.clonedUsers[index]; @@ -220,7 +213,29 @@ export class AutoRolesComponent implements OnInit { delete this.clonedUsers[index]; } - addUser(table: Table) { + deleteAutoRole(autoRole: AutoRole) { + this.confirmDialog.confirmDialog( + this.translate.instant("view.server.auto_roles.message.auto_role_delete"), this.translate.instant("view.server.auto_roles.message.auto_role_delete_q", { id: autoRole.id }), + () => { + this.spinner.showSpinner(); + this.data.mutation(Mutations.deleteAutoRole, { + id: autoRole.id + } + ).pipe(catchError(err => { + this.spinner.hideSpinner(); + this.toastService.error(this.translate.instant("view.server.auto_roles.message.auto_role_delete_failed"), this.translate.instant("view.server.auto_roles.message.auto_role_delete_failed_d", { id: autoRole.id })); + return throwError(err); + })).subscribe(_ => { + this.spinner.hideSpinner(); + this.toastService.success(this.translate.instant("view.server.auto_roles.message.auto_role_deleted"), this.translate.instant("view.server.auto_roles.message.auto_role_deleted_d", { id: autoRole.id })); + this.loadNextPage(); + }); + }); + + + } + + addAutoRole(table: Table) { const newAutoRole = JSON.parse(JSON.stringify(this.newAutoRoleTemplate)); newAutoRole.id = Math.max.apply(Math, this.auto_roles.map(u => { return u.id ?? 0; diff --git a/kdb-web/src/app/modules/view/server/members/members.component.html b/kdb-web/src/app/modules/view/server/members/members.component.html index 7170c8f5..1c120f02 100644 --- a/kdb-web/src/app/modules/view/server/members/members.component.html +++ b/kdb-web/src/app/modules/view/server/members/members.component.html @@ -163,7 +163,8 @@ - + {{member.xp}} diff --git a/kdb-web/src/app/services/data/data.service.ts b/kdb-web/src/app/services/data/data.service.ts index e0c36ef1..5a6b37ed 100644 --- a/kdb-web/src/app/services/data/data.service.ts +++ b/kdb-web/src/app/services/data/data.service.ts @@ -9,6 +9,7 @@ import { Queries } from "../../models/graphql/queries.model"; import { Query } from "../../models/graphql/query.model"; import { SidebarService } from "../sidebar/sidebar.service"; import { SpinnerService } from "../spinner/spinner.service"; +import { GraphQLResult } from "../../models/graphql/result.model"; @Injectable({ providedIn: "root" @@ -20,7 +21,7 @@ export class DataService { private http: HttpClient, private sidebar: SidebarService, private spinner: SpinnerService, - private router: Router, + private router: Router ) { } @@ -28,7 +29,7 @@ export class DataService { this.spinner.showSpinner(); if (!route.snapshot.params["serverId"]) { this.spinner.hideSpinner(); - this.router.navigate(['/dashboard']); + this.router.navigate(["/dashboard"]); return; } @@ -46,21 +47,31 @@ export class DataService { public query(query: string, variables?: Variables, f?: Function): Observable { return this.http - .post<{ data: T }>(`${this.appsettings.getApiURL()}/api/graphql`, { + .post(`${this.appsettings.getApiURL()}/api/graphql`, { query: query, variables: variables }) - .pipe(map((d) => d.data)) + .pipe(map(d => { + if (d.errors && d.errors.length > 0) { + throw new Error(d.errors.toString()); + } + return d.data; + })) .pipe(map((d) => f ? f(d) : d)); } public mutation(query: string, variables?: object, f?: Function): Observable { return this.http - .post<{ data: T }>(`${this.appsettings.getApiURL()}/api/graphql`, { + .post(`${this.appsettings.getApiURL()}/api/graphql`, { query: query, variables: variables }) - .pipe(map((d) => d.data)) + .pipe(map(d => { + if (d.errors && d.errors.length > 0) { + throw new Error(d.errors.toString()); + } + return d.data; + })) .pipe(map((d) => f ? f(d) : d)); } diff --git a/kdb-web/src/assets/i18n/de.json b/kdb-web/src/assets/i18n/de.json index eefd653d..9af9fa47 100644 --- a/kdb-web/src/assets/i18n/de.json +++ b/kdb-web/src/assets/i18n/de.json @@ -236,10 +236,16 @@ }, "no_entries_found": "Keine Einträge gefunden", "message": { - "user_changed": "Benutzer geändert", - "user_changed_d": "Benutzer {{name}} erfolgreich geändert", - "user_change_failed": "Benutzer änderung fehlgeschlagen", - "user_change_failed_d": "Benutzer {{name}} konnte nicht geändert werden!" + "auto_role_create": "Auto Rolle erstellt", + "auto_role_create_d": "Auto Rolle {{id}} erfolgreich erstellt", + "auto_role_create_failed": "Auto Rolle Erstellung fehlgeschlagen", + "auto_role_create_failed_d": "Die Erstellung der Auto Rolle ist fehlgeschlagen!", + "auto_role_delete": "Auto Rolle löschen", + "auto_role_delete_q": "Sind Sie sich sicher, dass Sie die Auto Rolle {{id}} löschen möchten?", + "auto_role_deleted": "Auto Rolle gelöscht", + "auto_role_deleted_d": "Auto Rolle {{id}} erfolgreich gelöscht", + "auto_role_delete_failed": "Auto Rolle Löschung fehlgeschlagen", + "auto_role_delete_failed_d": "Die Löschung der Auto Rolle {{id}} ist fehlgeschlagen!" } } }, diff --git a/kdb-web/src/styles/primeng-fixes.scss b/kdb-web/src/styles/primeng-fixes.scss index dccf88d9..506f1fee 100644 --- a/kdb-web/src/styles/primeng-fixes.scss +++ b/kdb-web/src/styles/primeng-fixes.scss @@ -97,6 +97,11 @@ p-table { } } +.p-dropdown, +.p-inputnumber { + width: 100% !important; +} + .pi-sort-alt:before { content: "\e915" !important; } diff --git a/kdb-web/src/styles/themes/default-dark-theme.scss b/kdb-web/src/styles/themes/default-dark-theme.scss index f0a7658b..c3b52930 100644 --- a/kdb-web/src/styles/themes/default-dark-theme.scss +++ b/kdb-web/src/styles/themes/default-dark-theme.scss @@ -580,4 +580,18 @@ background-color: $primaryBackgroundColor !important; color: $primaryHeaderColor !important; } + + .input-number { + span { + .p-button { + background-color: $primaryHeaderColor !important; + border: 1px solid $primaryHeaderColor !important; + + &:hover { + background-color: $secondaryHeaderColor !important; + border: 1px solid $secondaryHeaderColor !important; + } + } + } + } } diff --git a/kdb-web/src/styles/themes/default-light-theme.scss b/kdb-web/src/styles/themes/default-light-theme.scss index 4c37c304..2ae2814e 100644 --- a/kdb-web/src/styles/themes/default-light-theme.scss +++ b/kdb-web/src/styles/themes/default-light-theme.scss @@ -580,4 +580,18 @@ background-color: $primaryBackgroundColor !important; color: $primaryHeaderColor !important; } + + .input-number { + span { + .p-button { + background-color: $primaryHeaderColor !important; + border: 1px solid $primaryHeaderColor !important; + + &:hover { + background-color: $secondaryHeaderColor !important; + border: 1px solid $secondaryHeaderColor !important; + } + } + } + } } diff --git a/kdb-web/src/styles/themes/sh-edraft-dark-theme.scss b/kdb-web/src/styles/themes/sh-edraft-dark-theme.scss index d05d920f..3a3d6013 100644 --- a/kdb-web/src/styles/themes/sh-edraft-dark-theme.scss +++ b/kdb-web/src/styles/themes/sh-edraft-dark-theme.scss @@ -582,4 +582,18 @@ background-color: $primaryBackgroundColor !important; color: $primaryHeaderColor !important; } + + .input-number { + span { + .p-button { + background-color: $primaryHeaderColor !important; + border: 1px solid $primaryHeaderColor !important; + + &:hover { + background-color: $secondaryHeaderColor !important; + border: 1px solid $secondaryHeaderColor !important; + } + } + } + } } diff --git a/kdb-web/src/styles/themes/sh-edraft-light-theme.scss b/kdb-web/src/styles/themes/sh-edraft-light-theme.scss index 6d3e5f42..f6d389ea 100644 --- a/kdb-web/src/styles/themes/sh-edraft-light-theme.scss +++ b/kdb-web/src/styles/themes/sh-edraft-light-theme.scss @@ -580,4 +580,18 @@ background-color: $primaryBackgroundColor !important; color: $primaryHeaderColor !important; } + + .input-number { + span { + .p-button { + background-color: $primaryHeaderColor !important; + border: 1px solid $primaryHeaderColor !important; + + &:hover { + background-color: $secondaryHeaderColor !important; + border: 1px solid $secondaryHeaderColor !important; + } + } + } + } }