mirror of
https://github.com/the-draupnir-project/Draupnir.git
synced 2026-03-30 11:00:13 +00:00
Add --invite to unban command (#666)
This PR closes #622 by adding a `--invite` flag to the `unban` command. * Add --invite to `unban` command (untested) * Use RoomInviter to invite users in unban command. * Condense unban(+invite) log message --------- Signed-off-by: nexy7574 <git@nexy7574.co.uk> Co-authored-by: gnuxie <Gnuxie@protonmail.com>
This commit is contained in:
@@ -14,6 +14,7 @@ import {
|
||||
PolicyListConfig,
|
||||
PolicyRoomManager,
|
||||
PolicyRuleType,
|
||||
RoomInviter,
|
||||
RoomResolver,
|
||||
RoomUnbanner,
|
||||
SetRoomMembership,
|
||||
@@ -50,8 +51,10 @@ async function unbanUserFromRooms(
|
||||
setMembership,
|
||||
roomUnbanner,
|
||||
noop,
|
||||
roomInviter,
|
||||
}: DraupnirUnbanCommandContext,
|
||||
rule: MatrixGlob
|
||||
rule: MatrixGlob,
|
||||
invite: boolean = false
|
||||
) {
|
||||
await managementRoomOutput.logMessage(
|
||||
LogLevel.INFO,
|
||||
@@ -67,7 +70,8 @@ async function unbanUserFromRooms(
|
||||
await managementRoomOutput.logMessage(
|
||||
LogLevel.DEBUG,
|
||||
"Unban",
|
||||
`Unbanning ${member.userID} in ${revision.room.toRoomIDOrAlias()}`,
|
||||
`Unbanning ${member.userID} in ${revision.room.toRoomIDOrAlias()}` +
|
||||
(invite ? ", and re-inviting them." : ""),
|
||||
revision.room.toRoomIDOrAlias()
|
||||
);
|
||||
if (!noop) {
|
||||
@@ -75,6 +79,18 @@ async function unbanUserFromRooms(
|
||||
revision.room.toRoomIDOrAlias(),
|
||||
member.userID
|
||||
);
|
||||
const inviteResult = await roomInviter.inviteUser(
|
||||
revision.room,
|
||||
member.userID
|
||||
);
|
||||
if (isError(inviteResult)) {
|
||||
await managementRoomOutput.logMessage(
|
||||
LogLevel.WARN,
|
||||
"Unban",
|
||||
`Failed to re-invite ${member.userID} to ${revision.room.toRoomIDOrAlias()}`,
|
||||
revision.room.toRoomIDOrAlias()
|
||||
);
|
||||
}
|
||||
} else {
|
||||
await managementRoomOutput.logMessage(
|
||||
LogLevel.WARN,
|
||||
@@ -98,6 +114,7 @@ export type DraupnirUnbanCommandContext = {
|
||||
noop: boolean;
|
||||
roomUnbanner: RoomUnbanner;
|
||||
unlistedUserRedactionQueue: UnlistedUserRedactionQueue;
|
||||
roomInviter: RoomInviter;
|
||||
};
|
||||
|
||||
export const DraupnirUnbanCommand = describeCommand({
|
||||
@@ -140,6 +157,11 @@ export const DraupnirUnbanCommand = describeCommand({
|
||||
description:
|
||||
"Legacy, now redundant option to unban the user from all rooms.",
|
||||
},
|
||||
invite: {
|
||||
isFlag: true,
|
||||
description:
|
||||
"Re-invite the unbanned user to any rooms they were unbanned from.",
|
||||
},
|
||||
},
|
||||
},
|
||||
async executor(
|
||||
@@ -206,7 +228,11 @@ export const DraupnirUnbanCommand = describeCommand({
|
||||
if (isStringUserID(rawEnttiy)) {
|
||||
unlistedUserRedactionQueue.removeUser(rawEnttiy);
|
||||
}
|
||||
await unbanUserFromRooms(context, rule);
|
||||
await unbanUserFromRooms(
|
||||
context,
|
||||
rule,
|
||||
keywords.getKeywordValue("invite")
|
||||
);
|
||||
}
|
||||
return Ok(undefined);
|
||||
},
|
||||
@@ -225,6 +251,7 @@ DraupnirContextToCommandContextTranslator.registerTranslation(
|
||||
noop: draupnir.config.noop,
|
||||
roomUnbanner: draupnir.clientPlatform.toRoomUnbanner(),
|
||||
unlistedUserRedactionQueue: draupnir.unlistedUserRedactionQueue,
|
||||
roomInviter: draupnir.clientPlatform.toRoomInviter(),
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
PolicyRuleType,
|
||||
PowerLevelsEventContent,
|
||||
Recommendation,
|
||||
RoomInviter,
|
||||
RoomResolver,
|
||||
RoomUnbanner,
|
||||
describeProtectedRoomsSet,
|
||||
@@ -136,6 +137,11 @@ describe("Test the DraupnirUnbanCommand", function () {
|
||||
noop: false,
|
||||
roomUnbanner,
|
||||
unlistedUserRedactionQueue: createMock<UnlistedUserRedactionQueue>(),
|
||||
roomInviter: createMock<RoomInviter>({
|
||||
async inviteUser() {
|
||||
return Ok(undefined);
|
||||
},
|
||||
}),
|
||||
},
|
||||
{
|
||||
rest: ["spam"],
|
||||
|
||||
Reference in New Issue
Block a user