diff --git a/src/commands/HelpCommand.ts b/src/commands/HelpCommand.ts index 703d82b..a03b27c 100644 --- a/src/commands/HelpCommand.ts +++ b/src/commands/HelpCommand.ts @@ -68,6 +68,8 @@ export class HelpCommand implements ICommand { "!conference join <room> - Makes the bot join the given room.\n" + "!conference copymods <from> <to> - Copies the moderators from one room to another.\n" + "!conference widgets <aud> - Creates all widgets for the auditorium and its talks.\n" + + "!conferece powerlevels <user> <room> <powerlevel> - Assigns the given powerlevel to the given userid in the given room or room group. Run the " + + "command without a room and powerlevel to see a list of room groups. User must be in room to have pl elevated\n" + "" + ""; return this.client.replyHtmlNotice(roomId, event, htmlHelp); diff --git a/src/commands/InviteMeCommand.ts b/src/commands/InviteMeCommand.ts index 776364f..59e4c23 100644 --- a/src/commands/InviteMeCommand.ts +++ b/src/commands/InviteMeCommand.ts @@ -99,7 +99,7 @@ export class InviteMeCommand implements ICommand { /** * Render a (somewhat) pretty list of group names. */ - private prettyGroupNameList(roomGroups: Map>) { + public prettyGroupNameList(roomGroups: Map>) { const bySection = new Map(); // organise the groups into sections diff --git a/src/commands/PowerLevelCommand.ts b/src/commands/PowerLevelCommand.ts new file mode 100644 index 0000000..0a1a3c4 --- /dev/null +++ b/src/commands/PowerLevelCommand.ts @@ -0,0 +1,74 @@ +/* +Copyright 2024 The Matrix.org Foundation C.I.C. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import { ICommand } from "./ICommand"; +import { Conference } from "../Conference"; +import {ConferenceMatrixClient} from "../ConferenceMatrixClient"; +import {InviteMeCommand} from "./InviteMeCommand"; + +export class PowerLevelCommand implements ICommand { + + constructor(private readonly client: ConferenceMatrixClient, private readonly conference: Conference) { + } + + public readonly prefixes = ["powerlevels"]; + + public async run(managementRoomId: string, event: any, args: string[]) { + let targetId = args[0] + let pl = args[2] + + const IM = new InviteMeCommand(this.client, this.conference); + const roomGroups = await IM.roomGroups(); + console.log(roomGroups) + + if (!args.length) { + return this.client.replyHtmlNotice(managementRoomId, event, "Please specify a room ID or alias, or one of the room groups:\n" + IM.prettyGroupNameList(roomGroups)); + } + + if (roomGroups.has(args[1])) { + const group = roomGroups.get(args[1])!; + for (const roomId of group) { + try { + await this.client.setUserPowerLevel(targetId, roomId, Number(pl)); + } + catch (e) { + throw new Error(`Error setting power levels: in room ${roomId}, ${e.body}`) + } + await this.client.unstableApis.addReactionToEvent(roomId, event['event_id'], '✅'); + } + } else { + let targetRoomId; + try { + targetRoomId = await this.client.resolveRoom(args[1]); + } + catch (error) { + throw Error(`Error resolving room ${args[1]}`, {cause:error}) + } + try { + await this.client.setUserPowerLevel(targetRoomId, targetRoomId, Number(pl)); + } + catch (e) { + throw new Error(`Error setting power levels in room ${targetRoomId}: ${e.body}`) + } + } + + return this.client.replyHtmlNotice(managementRoomId, event, "Power levels sent") + } + +} + + + diff --git a/src/index.ts b/src/index.ts index 1e68e60..a805111 100644 --- a/src/index.ts +++ b/src/index.ts @@ -43,6 +43,7 @@ import { PermissionsCommand } from "./commands/PermissionsCommand"; import { VerifyCommand } from "./commands/VerifyCommand"; import { CustomLogger } from "./CustomLogger"; import { InviteMeCommand } from "./commands/InviteMeCommand"; +import { PowerLevelCommand } from "./commands/PowerLevelCommand"; import { WidgetsCommand } from "./commands/WidgetsCommand"; import { Scoreboard } from "./Scoreboard"; import { Scheduler } from "./Scheduler"; @@ -242,6 +243,7 @@ export class ConferenceBot { new HelpCommand(this.client), new InviteCommand(this.client, this.conference, this.config), new InviteMeCommand(this.client, this.conference), + new PowerLevelCommand(this.client, this.conference), new JoinCommand(this.client), new PermissionsCommand(this.client, this.conference), new RunCommand(this.client, this.conference, this.scheduler),