diff --git a/src/bot.ts b/src/bot.ts index 400bf1f146a7864baa2b02ab6cddc7b9b1f25821..56badb03b6291b712f974734495fdc4afcb541a6 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -25,7 +25,7 @@ import { Intent, MatrixUser, RemoteUser, - unstable, + Unstable, } from "matrix-appservice-bridge"; import { Util, wrap } from "./util"; import { @@ -432,7 +432,7 @@ export class DiscordBot { /** * Sends an event to Discord. - * @throws {unstable.ForeignNetworkError} + * @throws {Unstable.ForeignNetworkError} */ public async send( embedSet: IMatrixEventProcessorResult, @@ -458,7 +458,7 @@ export class DiscordBot { "Matrix Bridge: Allow rich user messages"); } } catch (err) { - throw wrap(err, unstable.ForeignNetworkError, "Unable to create \"_matrix\" webhook"); + throw wrap(err, Unstable.ForeignNetworkError, "Unable to create \"_matrix\" webhook"); } } try { @@ -485,7 +485,7 @@ export class DiscordBot { await this.StoreMessagesSent(msg, chan, event); this.unlockChannel(chan); } catch (err) { - throw wrap(err, unstable.ForeignNetworkError, "Couldn't send message"); + throw wrap(err, Unstable.ForeignNetworkError, "Couldn't send message"); } } diff --git a/src/discordas.ts b/src/discordas.ts index a470dff8eacd4cbc77707136dd7475d112bcc4e4..99b349e1e13a33a8cefa262283e8864cf06e26f9 100644 --- a/src/discordas.ts +++ b/src/discordas.ts @@ -22,7 +22,7 @@ import { ClientFactory, Request, thirdPartyLookup, - unstable, + unstable as Unstable, } from "matrix-appservice-bridge"; import * as yaml from "js-yaml"; import * as fs from "fs"; @@ -236,7 +236,7 @@ function logOnEventError(err: Error): void { const errTypes = []; // const warn = [EventInternalError, EventTooOldError, NotReadyError, …]; const infoTypes = []; - const verboseTypes = [unstable.EventUnknownError]; + const verboseTypes = [Unstable.EventUnknownError]; switch (true) { case instanceofsome(err, errTypes): log.error(err); @@ -255,7 +255,7 @@ function recordRequestOutcome(request: Request): void { .then(() => MetricPeg.get.requestOutcome(eventId, false, "success"), ) - .catch(unstable.EventNotHandledError, (e) => + .catch(Unstable.EventNotHandledError, (e) => MetricPeg.get.requestOutcome(eventId, false, "dropped"), ) .catch((e) => @@ -288,7 +288,7 @@ class NotReadyError extends Error { public name: string; constructor(...params) { - unstable.defaultMessage( + Unstable.defaultMessage( params, "The bridge was not ready when the message was sent", ); diff --git a/src/matrixeventprocessor.ts b/src/matrixeventprocessor.ts index 461a4f034d1c3a624f823b5fe74402483b251fc3..e5d13e581cfbbece0606a9981084fa1fef83cf93 100644 --- a/src/matrixeventprocessor.ts +++ b/src/matrixeventprocessor.ts @@ -26,7 +26,7 @@ import { BridgeContext, MatrixUser, Request, - unstable, + unstable as Unstable, } from "matrix-appservice-bridge"; import { Client as MatrixClient } from "matrix-js-sdk"; import { IMatrixEvent, IMatrixEventContent, IMatrixMessage } from "./matrixtypes"; @@ -82,12 +82,12 @@ 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 {unstable.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 unstable.EventTooOldError( + throw new Unstable.EventTooOldError( `Skipping event due to age ${event.unsigned.age} > ${AGE_LIMIT}`, ); } @@ -139,12 +139,12 @@ export class MatrixEventProcessor { await this.HandleEncryptionWarning(event.room_id); return; } catch (err) { - throw wrap(err, unstable.EventNotHandledError, `Failed to handle encrypted room, ${err}`); + throw wrap(err, Unstable.EventNotHandledError, `Failed to handle encrypted room, ${err}`); } } else { - throw new unstable.EventUnknownError("Got non m.room.message event"); + throw new Unstable.EventUnknownError("Got non m.room.message event"); } - throw new unstable.EventUnknownError(); // Shouldn't be reachable + throw new Unstable.EventUnknownError(); // Shouldn't be reachable } public async HandleEncryptionWarning(roomId: string): Promise<void> { @@ -171,7 +171,7 @@ export class MatrixEventProcessor { * * @param event The message event to process. * @param context Context of the bridge. - * @throws {unstable.ForeignNetworkError} + * @throws {Unstable.ForeignNetworkError} */ public async ProcessMsgEvent(event: IMatrixEvent, context: BridgeContext): Promise<void> { const room = context.rooms.remote; diff --git a/test/test_matrixeventprocessor.ts b/test/test_matrixeventprocessor.ts index 2738fb61629aedd766e45ccea2e9b1ddbadd8744..26080fbcd3cb65ef6d0405388a40c4b4c51c32c0 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 { unstable } from "matrix-appservice-bridge"; +import { unstable as 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(unstable.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(unstable.EventUnknownError); + expect(err).to.be.an.instanceof(Unstable.EventUnknownError); }); it("should handle own invites", async () => { const processor = createMatrixEventProcessor();