mirror of
https://github.com/matrix-org/mjolnir.git
synced 2024-10-01 05:36:06 +00:00
Add a command to resolve a room alias to a room ID
This commit is contained in:
parent
3dd4274b3b
commit
f5763803d9
@ -16,6 +16,7 @@ limitations under the License.
|
|||||||
|
|
||||||
import { Mjolnir } from "../Mjolnir";
|
import { Mjolnir } from "../Mjolnir";
|
||||||
import { RichReply } from "matrix-bot-sdk";
|
import { RichReply } from "matrix-bot-sdk";
|
||||||
|
import * as htmlEscape from "escape-html";
|
||||||
|
|
||||||
// !mjolnir move <alias> <new room ID>
|
// !mjolnir move <alias> <new room ID>
|
||||||
export async function execMoveAliasCommand(roomId: string, event: any, mjolnir: Mjolnir, parts: string[]) {
|
export async function execMoveAliasCommand(roomId: string, event: any, mjolnir: Mjolnir, parts: string[]) {
|
||||||
@ -72,3 +73,16 @@ export async function execRemoveAliasCommand(roomId: string, event: any, mjolnir
|
|||||||
|
|
||||||
await mjolnir.client.unstableApis.addReactionToEvent(roomId, event['event_id'], '✅');
|
await mjolnir.client.unstableApis.addReactionToEvent(roomId, event['event_id'], '✅');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// !mjolnir resolve <alias>
|
||||||
|
export async function execResolveCommand(roomId: string, event: any, mjolnir: Mjolnir, parts: string[]) {
|
||||||
|
const toResolve = parts[2];
|
||||||
|
|
||||||
|
const resolvedRoomId = await mjolnir.client.resolveRoom(toResolve);
|
||||||
|
|
||||||
|
const message = `Room ID for ${toResolve} is ${resolvedRoomId}`;
|
||||||
|
const html = `Room ID for ${htmlEscape(toResolve)} is ${htmlEscape(resolvedRoomId)}`;
|
||||||
|
const reply = RichReply.createFor(roomId, event, message, html);
|
||||||
|
reply["msgtype"] = "m.notice";
|
||||||
|
await mjolnir.client.sendMessage(roomId, reply);
|
||||||
|
}
|
||||||
|
@ -34,7 +34,7 @@ import { execAddProtectedRoom, execRemoveProtectedRoom } from "./AddRemoveProtec
|
|||||||
import { execAddRoomToDirectoryCommand, execRemoveRoomFromDirectoryCommand } from "./AddRemoveRoomFromDirectoryCommand";
|
import { execAddRoomToDirectoryCommand, execRemoveRoomFromDirectoryCommand } from "./AddRemoveRoomFromDirectoryCommand";
|
||||||
import { execSetPowerLevelCommand } from "./SetPowerLevelCommand";
|
import { execSetPowerLevelCommand } from "./SetPowerLevelCommand";
|
||||||
import { execShutdownRoomCommand } from "./ShutdownRoomCommand";
|
import { execShutdownRoomCommand } from "./ShutdownRoomCommand";
|
||||||
import { execAddAliasCommand, execMoveAliasCommand, execRemoveAliasCommand } from "./AliasCommands";
|
import { execAddAliasCommand, execMoveAliasCommand, execRemoveAliasCommand, execResolveCommand } from "./AliasCommands";
|
||||||
|
|
||||||
export const COMMAND_PREFIX = "!mjolnir";
|
export const COMMAND_PREFIX = "!mjolnir";
|
||||||
|
|
||||||
@ -91,6 +91,8 @@ export async function handleCommand(roomId: string, event: any, mjolnir: Mjolnir
|
|||||||
return await execAddAliasCommand(roomId, event, mjolnir, parts);
|
return await execAddAliasCommand(roomId, event, mjolnir, parts);
|
||||||
} else if (parts[1] === 'alias' && parts.length > 3 && parts[2] === 'remove') {
|
} else if (parts[1] === 'alias' && parts.length > 3 && parts[2] === 'remove') {
|
||||||
return await execRemoveAliasCommand(roomId, event, mjolnir, parts);
|
return await execRemoveAliasCommand(roomId, event, mjolnir, parts);
|
||||||
|
} else if (parts[1] === 'resolve' && parts.length > 2) {
|
||||||
|
return await execResolveCommand(roomId, event, mjolnir, parts);
|
||||||
} else if (parts[1] === 'powerlevel' && parts.length > 3) {
|
} else if (parts[1] === 'powerlevel' && parts.length > 3) {
|
||||||
return await execSetPowerLevelCommand(roomId, event, mjolnir, parts);
|
return await execSetPowerLevelCommand(roomId, event, mjolnir, parts);
|
||||||
} else if (parts[1] === 'shutdown' && parts[2] === 'room' && parts.length > 3) {
|
} else if (parts[1] === 'shutdown' && parts[2] === 'room' && parts.length > 3) {
|
||||||
@ -124,6 +126,7 @@ export async function handleCommand(roomId: string, event: any, mjolnir: Mjolnir
|
|||||||
"!mjolnir directory remove <room alias/ID> - Removes a room from the server's room directory\n" +
|
"!mjolnir directory remove <room alias/ID> - Removes a room from the server's room directory\n" +
|
||||||
"!mjolnir alias add <room alias> <target room alias/ID> - Adds <room alias> to <target room>\n" +
|
"!mjolnir alias add <room alias> <target room alias/ID> - Adds <room alias> to <target room>\n" +
|
||||||
"!mjolnir alias remove <room alias> - Deletes the room alias from whatever room it is attached to\n" +
|
"!mjolnir alias remove <room alias> - Deletes the room alias from whatever room it is attached to\n" +
|
||||||
|
"!mjolnir resolve <room alias> - Resolves a room alias to a room ID\n" +
|
||||||
"!mjolnir shutdown room <room alias/ID> - Uses the bot's account to shut down a room, preventing access to the room on this server\n" +
|
"!mjolnir shutdown room <room alias/ID> - Uses the bot's account to shut down a room, preventing access to the room on this server\n" +
|
||||||
"!mjolnir powerlevel <user ID> <power level> [room alias/ID] - Sets the power level of the user in the specified room (or all protected rooms)\n" +
|
"!mjolnir powerlevel <user ID> <power level> [room alias/ID] - Sets the power level of the user in the specified room (or all protected rooms)\n" +
|
||||||
"!mjolnir help - This menu\n";
|
"!mjolnir help - This menu\n";
|
||||||
|
Loading…
Reference in New Issue
Block a user