diff --git a/src/discordas.ts b/src/discordas.ts index f97e870f1fafa398230da4857eb9530144ec07ae..a470dff8eacd4cbc77707136dd7475d112bcc4e4 100644 --- a/src/discordas.ts +++ b/src/discordas.ts @@ -20,11 +20,9 @@ import { BridgeContext, Cli, ClientFactory, - EventNotHandledError, - EventUnknownError, Request, - default_message, thirdPartyLookup, + unstable, } from "matrix-appservice-bridge"; import * as yaml from "js-yaml"; import * as fs from "fs"; @@ -158,6 +156,7 @@ async function run(port: number, fileConfig: DiscordBridgeConfig) { dontJoin: true, // handled manually }, }, + networkName: "Discord", // To avoid out of order message sending. queue: { perRequest: true, @@ -237,7 +236,7 @@ function logOnEventError(err: Error): void { const errTypes = []; // const warn = [EventInternalError, EventTooOldError, NotReadyError, …]; const infoTypes = []; - const verboseTypes = [EventUnknownError]; + const verboseTypes = [unstable.EventUnknownError]; switch (true) { case instanceofsome(err, errTypes): log.error(err); @@ -256,7 +255,7 @@ function recordRequestOutcome(request: Request): void { .then(() => MetricPeg.get.requestOutcome(eventId, false, "success"), ) - .catch(EventNotHandledError, (e) => + .catch(unstable.EventNotHandledError, (e) => MetricPeg.get.requestOutcome(eventId, false, "dropped"), ) .catch((e) => @@ -289,7 +288,10 @@ class NotReadyError extends Error { public name: string; constructor(...params) { - default_message(params, "The bridge was not ready when the message was sent"); + unstable.defaultMessage( + params, + "The bridge was not ready when the message was sent", + ); super(...params); this.name = "NotReadyError"; } diff --git a/src/matrixeventprocessor.ts b/src/matrixeventprocessor.ts index e286cc14225698e6e9b319621f7baaa608d6d3d5..fcaa6503f70e346fce5d8ca14deea92de08d22ec 100644 --- a/src/matrixeventprocessor.ts +++ b/src/matrixeventprocessor.ts @@ -24,12 +24,9 @@ import * as mime from "mime"; import { Bridge, BridgeContext, - EventInternalError, - EventNotHandledError, - EventTooOldError, - EventUnknownError, MatrixUser, Request, + unstable, } from "matrix-appservice-bridge"; import { Client as MatrixClient } from "matrix-js-sdk"; import { IMatrixEvent, IMatrixEventContent, IMatrixMessage } from "./matrixtypes"; @@ -86,12 +83,14 @@ export class MatrixEventProcessor { * * @param request Request object containing the event for which this callback is called. * @param context The current context of the bridge. - * @throws {EventNotHandledError} When the event can finally not be handled. + * @throws {unstable.EventNotHandledError} When the event can finally not be handled. */ public async OnEvent(request: Request, context: BridgeContext): Promise<void> { const event = request.getData() as IMatrixEvent; if (event.unsigned.age > AGE_LIMIT) { - throw new EventTooOldError(`Skipping event due to age ${event.unsigned.age} > ${AGE_LIMIT}`); + throw new unstable.EventTooOldError( + `Skipping event due to age ${event.unsigned.age} > ${AGE_LIMIT}`, + ); } if ( event.type === "m.room.member" && @@ -153,12 +152,12 @@ export class MatrixEventProcessor { await this.HandleEncryptionWarning(event.room_id); return; } catch (err) { - throw wrap(err, EventNotHandledError, `Failed to handle encrypted room, ${err}`); + throw wrap(err, unstable.EventNotHandledError, `Failed to handle encrypted room, ${err}`); } } else { - throw new EventUnknownError("Got non m.room.message event"); + throw new unstable.EventUnknownError("Got non m.room.message event"); } - throw new EventUnknownError(); // Shouldn't be reachable + throw new unstable.EventUnknownError(); // Shouldn't be reachable } public async HandleEncryptionWarning(roomId: string): Promise<void> { diff --git a/test/test_matrixeventprocessor.ts b/test/test_matrixeventprocessor.ts index 149351a1a470987774d846f190f80542e5c9f2c4..8ac20bdf7b7a116c9449b98ca5f2824d126a713f 100644 --- a/test/test_matrixeventprocessor.ts +++ b/test/test_matrixeventprocessor.ts @@ -17,7 +17,7 @@ limitations under the License. import * as Chai from "chai"; import * as Discord from "discord.js"; import * as Proxyquire from "proxyquire"; -import { EventTooOldError, EventUnknownError} from "matrix-appservice-bridge"; +import { unstable } from "matrix-appservice-bridge"; import { PresenceHandler } from "../src/presencehandler"; import { DiscordBot } from "../src/bot"; @@ -818,7 +818,7 @@ This is the reply`, try { await processor.OnEvent(buildRequest({unsigned: {age: AGE}}), null); } catch (e) { err = e; } - expect(err).to.be.an.instanceof(EventTooOldError); + expect(err).to.be.an.instanceof(unstable.EventTooOldError); }); it("should reject un-processable events", async () => { const AGE = 900000; // 15 * 60 * 1000 @@ -834,7 +834,7 @@ This is the reply`, null, ); } catch (e) { err = e; } - expect(err).to.be.an.instanceof(EventUnknownError); + expect(err).to.be.an.instanceof(unstable.EventUnknownError); }); it("should handle own invites", async () => { const processor = createMatrixEventProcessor();