diff --git a/src/matrixeventprocessor.ts b/src/matrixeventprocessor.ts index e5d13e581cfbbece0606a9981084fa1fef83cf93..635b20cf55fdf6c0f50fec061b5d550135d485d8 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 e334c2c48180cfb03dabca000533f257e63d4a6e..f8da79e939dc26401ed577b91e05e06cfc8844d4 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") - ); -}