Skip to content
Extraits de code Groupes Projets
Valider 0baa1a30 rédigé par Kai A. Hiller's avatar Kai A. Hiller
Parcourir les fichiers

Move helper functions


Signed-off-by: default avatarKai A. Hiller <V02460@gmail.com>
parent e4273c05
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -18,13 +18,14 @@ import * as Discord from "discord.js"; ...@@ -18,13 +18,14 @@ import * as Discord from "discord.js";
import { DiscordBot } from "./bot"; import { DiscordBot } from "./bot";
import { DiscordBridgeConfig } from "./config"; import { DiscordBridgeConfig } from "./config";
import * as escapeStringRegexp from "escape-string-regexp"; 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 path from "path";
import * as mime from "mime"; import * as mime from "mime";
import { import {
Bridge, Bridge,
BridgeContext, BridgeContext,
MatrixUser, MatrixUser,
RemoteRoom,
Request, Request,
unstable as Unstable, unstable as Unstable,
} from "matrix-appservice-bridge"; } from "matrix-appservice-bridge";
...@@ -41,6 +42,7 @@ const MIN_NAME_LENGTH = 2; ...@@ -41,6 +42,7 @@ const MIN_NAME_LENGTH = 2;
const MAX_NAME_LENGTH = 32; const MAX_NAME_LENGTH = 32;
const DISCORD_AVATAR_WIDTH = 128; const DISCORD_AVATAR_WIDTH = 128;
const DISCORD_AVATAR_HEIGHT = 128; const DISCORD_AVATAR_HEIGHT = 128;
const ROOM_NAME_PARTS = 2;
const AGE_LIMIT = 900000; // 15 * 60 * 1000 const AGE_LIMIT = 900000; // 15 * 60 * 1000
export class MatrixEventProcessorOpts { export class MatrixEventProcessorOpts {
...@@ -476,3 +478,23 @@ export class MatrixEventProcessor { ...@@ -476,3 +478,23 @@ export class MatrixEventProcessor {
return "matrix-media." + mime.extension(content.info.mimetype); 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")
);
}
...@@ -16,7 +16,7 @@ limitations under the License. ...@@ -16,7 +16,7 @@ limitations under the License.
import * as http from "http"; import * as http from "http";
import * as https from "https"; import * as https from "https";
import { Intent, RemoteRoom } from "matrix-appservice-bridge"; import { Intent } from "matrix-appservice-bridge";
import { Buffer } from "buffer"; import { Buffer } from "buffer";
import * as mime from "mime"; import * as mime from "mime";
import { Permissions } from "discord.js"; import { Permissions } from "discord.js";
...@@ -453,24 +453,3 @@ export function wrap<T extends Error>( ...@@ -453,24 +453,3 @@ export function wrap<T extends Error>(
newError.message += ":\n" + appendMsg; newError.message += ":\n" + appendMsg;
return newError; 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")
);
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter