mirror of
https://github.com/the-draupnir-project/Draupnir.git
synced 2026-05-28 19:34:01 +00:00
Refactor and improve the unban command.
We no longer want to accept an argument for the list. We will just find all appropriate policies and remove them, like we do with the unban prompt (which we still might want to update to use the new `--no-confirm` prompt later). We fix the bugs where the unban command was inviting users regardless of whether the `--invite` option was provided. The unban command now uses a preview which shows all the policies that will have to be removed to unban a user, all the rooms they will need to be unbanned from, and any rooms that they will be invited to if the `--invite` option is used.
This commit is contained in:
@@ -11,7 +11,10 @@
|
||||
import { MatrixClient } from "matrix-bot-sdk";
|
||||
import { strict as assert } from "assert";
|
||||
import * as crypto from "crypto";
|
||||
import { MatrixEmitter } from "matrix-protection-suite-for-matrix-bot-sdk";
|
||||
import {
|
||||
MatrixEmitter,
|
||||
MatrixSendClient,
|
||||
} from "matrix-protection-suite-for-matrix-bot-sdk";
|
||||
import {
|
||||
NoticeMessageContent,
|
||||
ReactionEvent,
|
||||
@@ -21,6 +24,11 @@ import {
|
||||
StringEventIDSchema,
|
||||
} from "matrix-protection-suite";
|
||||
import { Type } from "@sinclair/typebox";
|
||||
import { Draupnir } from "../../../src/Draupnir";
|
||||
import {
|
||||
StringEventID,
|
||||
StringRoomID,
|
||||
} from "@the-draupnir-project/matrix-basic-types";
|
||||
|
||||
export const ReplyContent = Type.Intersect([
|
||||
Type.Object({
|
||||
@@ -249,3 +257,30 @@ export async function createBanList(
|
||||
);
|
||||
return listName;
|
||||
}
|
||||
|
||||
export async function sendCommand(
|
||||
draupnir: Draupnir,
|
||||
command: string
|
||||
): Promise<{ eventID: StringEventID }> {
|
||||
const eventID = (await draupnir.client.sendMessage(
|
||||
draupnir.managementRoomID,
|
||||
{
|
||||
msgtype: "m.text",
|
||||
body: command,
|
||||
}
|
||||
)) as StringEventID;
|
||||
return { eventID };
|
||||
}
|
||||
|
||||
export async function acceptPropmt(
|
||||
client: MatrixSendClient,
|
||||
roomID: StringRoomID,
|
||||
eventID: StringEventID,
|
||||
promptKey: string
|
||||
): Promise<void> {
|
||||
// i suspect that adding a reaction using the unstable API doesn't work because it uses the usntable prefix
|
||||
// whereas our schema doesn't have the unstable event type.
|
||||
// we don't test for this anywhere and we should really unify the situation between draupnir, draupnir safe mode,
|
||||
// and any new bots that just need all the same things.
|
||||
await client.unstableApis.addReactionToEvent(roomID, eventID, promptKey);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user