mirror of
https://github.com/matrix-org/mjolnir.git
synced 2024-10-01 01:36:06 -04:00
Add alias add/remove commands
Fixes https://github.com/matrix-org/mjolnir/issues/42
This commit is contained in:
parent
39903ee298
commit
3dd4274b3b
@ -36,3 +36,39 @@ export async function execMoveAliasCommand(roomId: string, event: any, mjolnir:
|
||||
|
||||
await mjolnir.client.unstableApis.addReactionToEvent(roomId, event['event_id'], '✅');
|
||||
}
|
||||
|
||||
// !mjolnir alias add <alias> <target room>
|
||||
export async function execAddAliasCommand(roomId: string, event: any, mjolnir: Mjolnir, parts: string[]) {
|
||||
const aliasToAdd = parts[3];
|
||||
const targetRoom = parts[4];
|
||||
|
||||
const isAdmin = await mjolnir.isSynapseAdmin();
|
||||
if (!isAdmin) {
|
||||
const message = "I am not a Synapse administrator, or the endpoint is blocked";
|
||||
const reply = RichReply.createFor(roomId, event, message, message);
|
||||
reply['msgtype'] = "m.notice";
|
||||
return mjolnir.client.sendMessage(roomId, reply);
|
||||
}
|
||||
|
||||
const newRoomId = await mjolnir.client.resolveRoom(targetRoom);
|
||||
await mjolnir.client.createRoomAlias(aliasToAdd, newRoomId);
|
||||
|
||||
await mjolnir.client.unstableApis.addReactionToEvent(roomId, event['event_id'], '✅');
|
||||
}
|
||||
|
||||
// !mjolnir alias remove <alias>
|
||||
export async function execRemoveAliasCommand(roomId: string, event: any, mjolnir: Mjolnir, parts: string[]) {
|
||||
const aliasToRemove = parts[3];
|
||||
|
||||
const isAdmin = await mjolnir.isSynapseAdmin();
|
||||
if (!isAdmin) {
|
||||
const message = "I am not a Synapse administrator, or the endpoint is blocked";
|
||||
const reply = RichReply.createFor(roomId, event, message, message);
|
||||
reply['msgtype'] = "m.notice";
|
||||
return mjolnir.client.sendMessage(roomId, reply);
|
||||
}
|
||||
|
||||
await mjolnir.client.deleteRoomAlias(aliasToRemove);
|
||||
|
||||
await mjolnir.client.unstableApis.addReactionToEvent(roomId, event['event_id'], '✅');
|
||||
}
|
@ -31,10 +31,10 @@ import { execDeactivateCommand } from "./DeactivateCommand";
|
||||
import { execDisableProtection, execEnableProtection, execListProtections } from "./ProtectionsCommands";
|
||||
import { execListProtectedRooms } from "./ListProtectedRoomsCommand";
|
||||
import { execAddProtectedRoom, execRemoveProtectedRoom } from "./AddRemoveProtectedRoomsCommand";
|
||||
import { execMoveAliasCommand } from "./MoveAliasCommand";
|
||||
import { execAddRoomToDirectoryCommand, execRemoveRoomFromDirectoryCommand } from "./AddRemoveRoomFromDirectoryCommand";
|
||||
import { execSetPowerLevelCommand } from "./SetPowerLevelCommand";
|
||||
import { execShutdownRoomCommand } from "./ShutdownRoomCommand";
|
||||
import { execAddAliasCommand, execMoveAliasCommand, execRemoveAliasCommand } from "./AliasCommands";
|
||||
|
||||
export const COMMAND_PREFIX = "!mjolnir";
|
||||
|
||||
@ -87,6 +87,10 @@ export async function handleCommand(roomId: string, event: any, mjolnir: Mjolnir
|
||||
return await execAddRoomToDirectoryCommand(roomId, event, mjolnir, parts);
|
||||
} else if (parts[1] === 'directory' && parts.length > 3 && parts[2] === 'remove') {
|
||||
return await execRemoveRoomFromDirectoryCommand(roomId, event, mjolnir, parts);
|
||||
} else if (parts[1] === 'alias' && parts.length > 4 && parts[2] === 'add') {
|
||||
return await execAddAliasCommand(roomId, event, mjolnir, parts);
|
||||
} else if (parts[1] === 'alias' && parts.length > 3 && parts[2] === 'remove') {
|
||||
return await execRemoveAliasCommand(roomId, event, mjolnir, parts);
|
||||
} else if (parts[1] === 'powerlevel' && parts.length > 3) {
|
||||
return await execSetPowerLevelCommand(roomId, event, mjolnir, parts);
|
||||
} else if (parts[1] === 'shutdown' && parts[2] === 'room' && parts.length > 3) {
|
||||
@ -118,6 +122,8 @@ export async function handleCommand(roomId: string, event: any, mjolnir: Mjolnir
|
||||
"!mjolnir move <room alias> <room alias/ID> - Moves a <room alias> to a new <room ID>\n" +
|
||||
"!mjolnir directory add <room alias/ID> - Publishes a room in 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 remove <room alias> - Deletes the room alias from whatever room it is attached to\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 help - This menu\n";
|
||||
|
Loading…
Reference in New Issue
Block a user