Sélectionner une révision Git
matrixeventprocessor.ts
matrixeventprocessor.ts 22,40 Kio
/*
Copyright 2018, 2019 matrix-appservice-discord
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import * as Discord from "better-discord.js"
import { DiscordBot } from "./bot";
import { DiscordBridgeConfig } from "./config";
import { Util, wrapError } from "./util";
import * as path from "path";
import * as mime from "mime";
import { IMatrixEvent, IMatrixEventContent, IMatrixMessage } from "./matrixtypes";
import { MatrixMessageProcessor, IMatrixMessageProcessorParams } from "./matrixmessageprocessor";
import { MatrixCommandHandler } from "./matrixcommandhandler";
import { DbEvent } from "./db/dbdataevent";
import { Log } from "./log";
import { IRoomStoreEntry, RemoteStoreRoom } from "./db/roomstore";
import { Appservice, MatrixClient } from "matrix-bot-sdk";
import { DiscordStore } from "./store";
import { TimedCache } from "./structures/timedcache";
const log = new Log("MatrixEventProcessor");
const MaxFileSize = 8000000;
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
const PROFILE_CACHE_LIFETIME = 900000;
export class MatrixEventProcessorOpts {
constructor(
readonly config: DiscordBridgeConfig,
readonly bridge: Appservice,
readonly discord: DiscordBot,
readonly store: DiscordStore,
) {
}
}
export interface IMatrixEventProcessorResult {
messageEmbed: Discord.MessageEmbed;
replyEmbed?: Discord.MessageEmbed;
imageEmbed?: Discord.MessageEmbed;
}
export class MatrixEventProcessor {
private config: DiscordBridgeConfig;
private bridge: Appservice;
private discord: DiscordBot;
private store: DiscordStore;
private matrixMsgProcessor: MatrixMessageProcessor;
private mxCommandHandler: MatrixCommandHandler;
private mxUserProfileCache: TimedCache<string, {displayname: string, avatar_url: string|undefined}>;