From 0baa1a3063bbbd28205fda415930644172de8fcf Mon Sep 17 00:00:00 2001 From: "Kai A. Hiller" <V02460@gmail.com> Date: Wed, 7 Aug 2019 10:17:03 -0400 Subject: [PATCH] Move helper functions Signed-off-by: Kai A. Hiller <V02460@gmail.com> --- src/matrixeventprocessor.ts | 24 +++++++++++++++++++++++- src/util.ts | 23 +---------------------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/matrixeventprocessor.ts b/src/matrixeventprocessor.ts index e5d13e5..635b20c 100644 --- a/src/matrixeventprocessor.ts +++ b/src/matrixeventprocessor.ts @@ -18,13 +18,14 @@ import * as Discord from "discord.js"; import { DiscordBot } from "./bot"; import { DiscordBridgeConfig } from "./config"; import * as escapeStringRegexp from "escape-string-regexp"; -import { Util, guildAndChannelOf, isBotCommand, wrap } from "./util"; +import { Util, wrap } from "./util"; import * as path from "path"; import * as mime from "mime"; import { Bridge, BridgeContext, MatrixUser, + RemoteRoom, Request, unstable as Unstable, } from "matrix-appservice-bridge"; @@ -41,6 +42,7 @@ const MIN_NAME_LENGTH = 2; const MAX_NAME_LENGTH = 32; const DISCORD_AVATAR_WIDTH = 128; const DISCORD_AVATAR_HEIGHT = 128; +const ROOM_NAME_PARTS = 2; const AGE_LIMIT = 900000; // 15 * 60 * 1000 export class MatrixEventProcessorOpts { @@ -476,3 +478,23 @@ export class MatrixEventProcessor { return "matrix-media." + mime.extension(content.info.mimetype); } } + +/** + * Returns the guild and channel of the given remote room extracted from its ID. + * @param remoteRoom The room from which to get the guild and channel. + * @returns (guild, channel)-tuple. + */ +function guildAndChannelOf(remoteRoom: RemoteRoom): [string, string] { + return remoteRoom.roomId.substr("_discord".length).split("_", ROOM_NAME_PARTS); +} + +/** + * Returns true if the given event is a bot command. + */ +function isBotCommand(event: IMatrixEvent): boolean { + return !!( + event.type === "m.room.message" && + event.content!.body && + event.content!.body!.startsWith("!discord") + ); +} diff --git a/src/util.ts b/src/util.ts index e334c2c..f8da79e 100644 --- a/src/util.ts +++ b/src/util.ts @@ -16,7 +16,7 @@ limitations under the License. import * as http from "http"; import * as https from "https"; -import { Intent, RemoteRoom } from "matrix-appservice-bridge"; +import { Intent } from "matrix-appservice-bridge"; import { Buffer } from "buffer"; import * as mime from "mime"; import { Permissions } from "discord.js"; @@ -453,24 +453,3 @@ export function wrap<T extends Error>( newError.message += ":\n" + appendMsg; return newError; } - -/** - * Returns the guild and channel of the given remote room extracted from its ID. - * @param remoteRoom The room from which to get the guild and channel. - * @returns (guild, channel)-tuple. - */ -export function guildAndChannelOf(remoteRoom: RemoteRoom): [string, string] { - const ROOM_NAME_PARTS = 2; - return remoteRoom.roomId.substr("_discord".length).split("_", ROOM_NAME_PARTS); -} - -/** - * Returns true if the given event is a bot command. - */ -export function isBotCommand(event: IMatrixEvent): boolean { - return !!( - event.type === "m.room.message" && - event.content!.body && - event.content!.body!.startsWith("!discord") - ); -} -- GitLab