mirror of
https://github.com/the-draupnir-project/Draupnir.git
synced 2026-04-28 03:45:29 +00:00
Update matrix-bot-sdk and use request cleaning function
This commit is contained in:
+1
-1
@@ -26,6 +26,6 @@
|
||||
"config": "^3.3.6",
|
||||
"escape-html": "^1.0.3",
|
||||
"js-yaml": "^4.1.0",
|
||||
"matrix-bot-sdk": "^0.5.18"
|
||||
"matrix-bot-sdk": "^0.5.19"
|
||||
}
|
||||
}
|
||||
|
||||
+20
-11
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2019, 2020 The Matrix.org Foundation C.I.C.
|
||||
Copyright 2019-2021 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@@ -14,7 +14,16 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { CreateEvent, LogLevel, LogService, MatrixClient, MatrixGlob, Permalinks, UserID } from "matrix-bot-sdk";
|
||||
import {
|
||||
CreateEvent,
|
||||
extractRequestError,
|
||||
LogLevel,
|
||||
LogService,
|
||||
MatrixClient,
|
||||
MatrixGlob,
|
||||
Permalinks,
|
||||
UserID
|
||||
} from "matrix-bot-sdk";
|
||||
import BanList, { ALL_RULE_TYPES } from "./models/BanList";
|
||||
import { applyServerAcls } from "./actions/ApplyAcl";
|
||||
import { RoomUpdateError } from "./models/RoomUpdateError";
|
||||
@@ -152,7 +161,7 @@ export class Mjolnir {
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
LogService.warn("Mjolnir", e);
|
||||
LogService.warn("Mjolnir", extractRequestError(e));
|
||||
}
|
||||
await this.buildWatchedBanLists();
|
||||
this.applyUnprotectedRooms();
|
||||
@@ -175,7 +184,7 @@ export class Mjolnir {
|
||||
}).catch(async err => {
|
||||
try {
|
||||
LogService.error("Mjolnir", "Error during startup:");
|
||||
LogService.error("Mjolnir", err);
|
||||
LogService.error("Mjolnir", extractRequestError(err));
|
||||
await logMessage(LogLevel.ERROR, "Mjolnir@startup", "Startup failed due to error - see console");
|
||||
} catch (e) {
|
||||
// If we failed to handle the error, just crash
|
||||
@@ -196,7 +205,7 @@ export class Mjolnir {
|
||||
try {
|
||||
additionalProtectedRooms = await this.client.getAccountData(PROTECTED_ROOMS_EVENT_TYPE);
|
||||
} catch (e) {
|
||||
LogService.warn("Mjolnir", e);
|
||||
LogService.warn("Mjolnir", extractRequestError(e));
|
||||
}
|
||||
if (!additionalProtectedRooms || !additionalProtectedRooms['rooms']) additionalProtectedRooms = {rooms: []};
|
||||
additionalProtectedRooms.rooms.push(roomId);
|
||||
@@ -214,7 +223,7 @@ export class Mjolnir {
|
||||
try {
|
||||
additionalProtectedRooms = await this.client.getAccountData(PROTECTED_ROOMS_EVENT_TYPE);
|
||||
} catch (e) {
|
||||
LogService.warn("Mjolnir", e);
|
||||
LogService.warn("Mjolnir", extractRequestError(e));
|
||||
}
|
||||
if (!additionalProtectedRooms || !additionalProtectedRooms['rooms']) additionalProtectedRooms = {rooms: []};
|
||||
additionalProtectedRooms.rooms = additionalProtectedRooms.rooms.filter(r => r !== roomId);
|
||||
@@ -250,7 +259,7 @@ export class Mjolnir {
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
LogService.warn("Mjolnir", e);
|
||||
LogService.warn("Mjolnir", extractRequestError(e));
|
||||
}
|
||||
|
||||
return enabled;
|
||||
@@ -261,7 +270,7 @@ export class Mjolnir {
|
||||
try {
|
||||
this.enableProtection(protection, false);
|
||||
} catch (e) {
|
||||
LogService.warn("Mjolnir", e);
|
||||
LogService.warn("Mjolnir", extractRequestError(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -464,7 +473,7 @@ export class Mjolnir {
|
||||
|
||||
// Otherwise OK
|
||||
} catch (e) {
|
||||
LogService.error("Mjolnir", e);
|
||||
LogService.error("Mjolnir", extractRequestError(e));
|
||||
errors.push({
|
||||
roomId,
|
||||
errorMessage: e.message || (e.body ? e.body.error : '<no message>'),
|
||||
@@ -559,7 +568,7 @@ export class Mjolnir {
|
||||
const eventPermalink = Permalinks.forEvent(roomId, event['event_id']);
|
||||
LogService.error("Mjolnir", "Error handling protection: " + protection.name);
|
||||
LogService.error("Mjolnir", "Failed event: " + eventPermalink);
|
||||
LogService.error("Mjolnir", e);
|
||||
LogService.error("Mjolnir", extractRequestError(e));
|
||||
await this.client.sendNotice(config.managementRoom, "There was an error processing an event through a protection - see log for details. Event: " + eventPermalink);
|
||||
}
|
||||
}
|
||||
@@ -631,7 +640,7 @@ export class Mjolnir {
|
||||
return response['admin'];
|
||||
} catch (e) {
|
||||
LogService.error("Mjolnir", "Error determining if Mjolnir is a server admin:");
|
||||
LogService.error("Mjolnir", e);
|
||||
LogService.error("Mjolnir", extractRequestError(e));
|
||||
return false; // assume not
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2020 The Matrix.org Foundation C.I.C.
|
||||
Copyright 2020-2021 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@@ -15,7 +15,7 @@ limitations under the License.
|
||||
*/
|
||||
|
||||
import { Mjolnir } from "../Mjolnir";
|
||||
import { LogLevel, LogService } from "matrix-bot-sdk";
|
||||
import { extractRequestError, LogLevel, LogService } from "matrix-bot-sdk";
|
||||
import { logMessage } from "../LogProxy";
|
||||
|
||||
// !mjolnir rooms add <room alias/ID>
|
||||
@@ -32,7 +32,7 @@ export async function execRemoveProtectedRoom(roomId: string, event: any, mjolni
|
||||
try {
|
||||
await mjolnir.client.leaveRoom(protectedRoomId);
|
||||
} catch (e) {
|
||||
LogService.warn("AddRemoveProtectedRoomsCommand", e);
|
||||
LogService.warn("AddRemoveProtectedRoomsCommand", extractRequestError(e));
|
||||
await logMessage(LogLevel.WARN, "AddRemoveProtectedRoomsCommand", `Failed to leave ${protectedRoomId} - the room is no longer being protected, but the bot could not leave`, protectedRoomId);
|
||||
}
|
||||
await mjolnir.client.unstableApis.addReactionToEvent(roomId, event['event_id'], '✅');
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2019, 2020 The Matrix.org Foundation C.I.C.
|
||||
Copyright 2019-2021 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@@ -18,7 +18,7 @@ import { Mjolnir } from "../Mjolnir";
|
||||
import { execStatusCommand } from "./StatusCommand";
|
||||
import { execBanCommand, execUnbanCommand } from "./UnbanBanCommand";
|
||||
import { execDumpRulesCommand } from "./DumpRulesCommand";
|
||||
import { LogService, RichReply } from "matrix-bot-sdk";
|
||||
import { extractRequestError, LogService, RichReply } from "matrix-bot-sdk";
|
||||
import * as htmlEscape from "escape-html";
|
||||
import { execSyncCommand } from "./SyncCommand";
|
||||
import { execPermissionCheckCommand } from "./PermissionCheckCommand";
|
||||
@@ -141,7 +141,7 @@ export async function handleCommand(roomId: string, event: any, mjolnir: Mjolnir
|
||||
return await mjolnir.client.sendMessage(roomId, reply);
|
||||
}
|
||||
} catch (e) {
|
||||
LogService.error("CommandHandler", e);
|
||||
LogService.error("CommandHandler", extractRequestError(e));
|
||||
const text = "There was an error processing your command - see console/log for details";
|
||||
const reply = RichReply.createFor(roomId, event, text, text);
|
||||
reply["msgtype"] = "m.notice";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2019 The Matrix.org Foundation C.I.C.
|
||||
Copyright 2019-2021 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@@ -15,7 +15,7 @@ limitations under the License.
|
||||
*/
|
||||
|
||||
import { Mjolnir } from "../Mjolnir";
|
||||
import { LogService, RichReply } from "matrix-bot-sdk";
|
||||
import { extractRequestError, LogService, RichReply } from "matrix-bot-sdk";
|
||||
import { PROTECTIONS } from "../protections/protections";
|
||||
|
||||
// !mjolnir enable <protection>
|
||||
@@ -24,7 +24,7 @@ export async function execEnableProtection(roomId: string, event: any, mjolnir:
|
||||
await mjolnir.enableProtection(parts[2]);
|
||||
await mjolnir.client.unstableApis.addReactionToEvent(roomId, event['event_id'], '✅');
|
||||
} catch (e) {
|
||||
LogService.error("ProtectionsCommands", e);
|
||||
LogService.error("ProtectionsCommands", extractRequestError(e));
|
||||
|
||||
const message = `Error enabling protection '${parts[0]}' - check the name and try again.`;
|
||||
const reply = RichReply.createFor(roomId, event, message, message);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2020 The Matrix.org Foundation C.I.C.
|
||||
Copyright 2020-2021 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@@ -15,7 +15,7 @@ limitations under the License.
|
||||
*/
|
||||
|
||||
import { Mjolnir } from "../Mjolnir";
|
||||
import { LogLevel, LogService } from "matrix-bot-sdk";
|
||||
import { extractRequestError, LogLevel, LogService } from "matrix-bot-sdk";
|
||||
import { logMessage } from "../LogProxy";
|
||||
|
||||
// !mjolnir powerlevel <user ID> <level> [room]
|
||||
@@ -32,7 +32,7 @@ export async function execSetPowerLevelCommand(roomId: string, event: any, mjoln
|
||||
} catch (e) {
|
||||
const message = e.message || (e.body ? e.body.error : '<no message>');
|
||||
await logMessage(LogLevel.ERROR, "SetPowerLevelCommand", `Failed to set power level of ${victim} to ${level} in ${targetRoomId}: ${message}`, targetRoomId);
|
||||
LogService.error("SetPowerLevelCommand", e);
|
||||
LogService.error("SetPowerLevelCommand", extractRequestError(e));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2019, 2020 The Matrix.org Foundation C.I.C.
|
||||
Copyright 2019-2021 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@@ -16,7 +16,7 @@ limitations under the License.
|
||||
|
||||
import { Mjolnir } from "../Mjolnir";
|
||||
import BanList, { RULE_ROOM, RULE_SERVER, RULE_USER, USER_RULE_TYPES } from "../models/BanList";
|
||||
import { LogLevel, LogService, MatrixGlob, RichReply } from "matrix-bot-sdk";
|
||||
import { extractRequestError, LogLevel, LogService, MatrixGlob, RichReply } from "matrix-bot-sdk";
|
||||
import { RECOMMENDATION_BAN, recommendationToStable } from "../models/ListRule";
|
||||
import config from "../config";
|
||||
import { logMessage } from "../LogProxy";
|
||||
@@ -37,7 +37,7 @@ export async function parseArguments(roomId: string, event: any, mjolnir: Mjolni
|
||||
defaultShortcode = data['shortcode'];
|
||||
} catch (e) {
|
||||
LogService.warn("UnbanBanCommand", "Non-fatal error getting default ban list");
|
||||
LogService.warn("UnbanBanCommand", e);
|
||||
LogService.warn("UnbanBanCommand", extractRequestError(e));
|
||||
|
||||
// Assume no default.
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2019 The Matrix.org Foundation C.I.C.
|
||||
Copyright 2019-2021 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { LogService, MatrixClient } from "matrix-bot-sdk";
|
||||
import { extractRequestError, LogService, MatrixClient } from "matrix-bot-sdk";
|
||||
import { ListRule } from "./ListRule";
|
||||
|
||||
export const RULE_USER = "m.room.rule.user";
|
||||
@@ -50,7 +50,7 @@ export default class BanList {
|
||||
const currentShortcode = this.shortcode;
|
||||
this.shortcode = newShortcode;
|
||||
this.client.sendStateEvent(this.roomId, SHORTCODE_EVENT_TYPE, '', {shortcode: this.shortcode}).catch(err => {
|
||||
LogService.error("BanList", err);
|
||||
LogService.error("BanList", extractRequestError(err));
|
||||
if (this.shortcode === newShortcode) this.shortcode = currentShortcode;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2019 The Matrix.org Foundation C.I.C.
|
||||
Copyright 2019-2021 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { LogLevel, LogService, MatrixClient, Permalinks } from "matrix-bot-sdk";
|
||||
import { extractRequestError, LogLevel, LogService, MatrixClient, Permalinks } from "matrix-bot-sdk";
|
||||
import { logMessage } from "../LogProxy";
|
||||
import config from "../config";
|
||||
|
||||
@@ -44,7 +44,7 @@ export class AutomaticRedactionQueue {
|
||||
}
|
||||
} catch (e) {
|
||||
logMessage(LogLevel.WARN, "AutomaticRedactionQueue", `Unable to redact message: ${permalink}`);
|
||||
LogService.warn("AutomaticRedactionQueue", e);
|
||||
LogService.warn("AutomaticRedactionQueue", extractRequestError(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2019, 2020 The Matrix.org Foundation C.I.C.
|
||||
Copyright 2019-2021 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@@ -15,6 +15,7 @@ limitations under the License.
|
||||
*/
|
||||
|
||||
import {
|
||||
extractRequestError,
|
||||
LogLevel,
|
||||
LogService,
|
||||
MatrixClient,
|
||||
@@ -194,7 +195,7 @@ export async function replaceRoomIdsWithPills(client: MatrixClient, text: string
|
||||
} catch (e) {
|
||||
// This is a recursive call, so tell the function not to try and call us
|
||||
await logMessage(LogLevel.WARN, "utils", `Failed to resolve room alias for ${roomId} - see console for details`, null, true);
|
||||
LogService.warn("utils", e);
|
||||
LogService.warn("utils", extractRequestError(e));
|
||||
}
|
||||
const regexRoomId = new RegExp(escapeRegex(roomId), "g");
|
||||
content.body = content.body.replace(regexRoomId, alias);
|
||||
|
||||
@@ -1261,10 +1261,10 @@ make-error@^1.1.1:
|
||||
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.5.tgz#efe4e81f6db28cadd605c70f29c831b58ef776c8"
|
||||
integrity sha512-c3sIjNUow0+8swNwVpqoH4YCShKNFkMaw6oH1mNS2haDZQqkeZFlHS3dhoeEbKKmJB4vXpJucU6oH75aDYeE9g==
|
||||
|
||||
matrix-bot-sdk@^0.5.18:
|
||||
version "0.5.18"
|
||||
resolved "https://registry.yarnpkg.com/matrix-bot-sdk/-/matrix-bot-sdk-0.5.18.tgz#c4e4e657fd632604380fce7453370d659a6f1d88"
|
||||
integrity sha512-NntJoGmZdGlBsJ+HuEi1zB0lcRd8BCiPH6hExeuRNKtMOVHhJIKUgd5IY2cTy5YxHGk+kbBbkpzooFvRxVkOrg==
|
||||
matrix-bot-sdk@^0.5.19:
|
||||
version "0.5.19"
|
||||
resolved "https://registry.yarnpkg.com/matrix-bot-sdk/-/matrix-bot-sdk-0.5.19.tgz#6ce13359ab53ea0af9dc3ebcbe288c5f6d9c02c6"
|
||||
integrity sha512-RIPyvQPkOVp2yTKeDgp5rcn6z/DiKdHb6E8c69K+utai8ypRGtfDRj0PGqP+1XzqC9Wb1OFrESCUB5t0ffdC9g==
|
||||
dependencies:
|
||||
"@types/express" "^4.17.7"
|
||||
chalk "^4.1.0"
|
||||
|
||||
Reference in New Issue
Block a user