handle and log failures to enact consequences

This commit is contained in:
jesopo 2022-09-23 09:43:20 +00:00
parent 55fc94c4c2
commit 30eab1991b

View File

@ -952,30 +952,34 @@ export class Mjolnir {
private async handleConsequences(protection: Protection, roomId: string, eventId: string, sender: string, consequences: Consequence[]) { private async handleConsequences(protection: Protection, roomId: string, eventId: string, sender: string, consequences: Consequence[]) {
for (const consequence of consequences) { for (const consequence of consequences) {
if (consequence.name === "alert") { try {
/* take no additional action, just print the below message to management room */ if (consequence.name === "alert") {
} else if (consequence.name === "ban") { /* take no additional action, just print the below message to management room */
await this.client.banUser(sender, roomId, "abuse detected"); } else if (consequence.name === "ban") {
} else if (consequence.name === "redact") { await this.client.banUser(sender, roomId, "abuse detected");
await this.client.redactEvent(roomId, eventId, "abuse detected"); } else if (consequence.name === "redact") {
} else { await this.client.redactEvent(roomId, eventId, "abuse detected");
throw new Error(`unknown consequence ${consequence.name}`); } else {
} throw new Error(`unknown consequence ${consequence.name}`);
let message = `protection ${protection.name} enacting`
+ ` ${consequence.name}`
+ ` against ${htmlEscape(sender)}`
+ ` in ${htmlEscape(roomId)}`
+ ` (reason: ${htmlEscape(consequence.reason)})`;
await this.client.sendMessage(this.managementRoomId, {
msgtype: "m.notice",
body: message,
[CONSEQUENCE_EVENT_DATA]: {
who: sender,
room: roomId,
types: [consequence.name],
} }
});
let message = `protection ${protection.name} enacting`
+ ` ${consequence.name}`
+ ` against ${htmlEscape(sender)}`
+ ` in ${htmlEscape(roomId)}`
+ ` (reason: ${htmlEscape(consequence.reason)})`;
await this.client.sendMessage(this.managementRoomId, {
msgtype: "m.notice",
body: message,
[CONSEQUENCE_EVENT_DATA]: {
who: sender,
room: roomId,
types: [consequence.name],
}
});
} catch (e) {
await this.logMessage(LogLevel.ERROR, "handleConsequences", `Failed to enact ${consequence.name} consequence: ${e}`);
}
} }
} }