Sélectionner une révision Git
matrixmessageprocessor.ts
matrixmessageprocessor.ts 4,98 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 { IMatrixMessage } from "./matrixtypes";
import { Util } from "./util";
import { DiscordBot } from "./bot";
import { MatrixClient } from "matrix-bot-sdk";
import { DiscordBridgeConfig } from "./config";
import {
IMatrixMessageParserCallbacks,
IMatrixMessageParserOpts,
MatrixMessageParser,
} from "@deurstann/matrix-discord-parser";
const DEFAULT_ROOM_NOTIFY_POWER_LEVEL = 50;
export interface IMatrixMessageProcessorParams {
displayname?: string;
mxClient?: MatrixClient;
roomId?: string;
userId?: string;
}
export class MatrixMessageProcessor {
private parser: MatrixMessageParser;
constructor(public bot: DiscordBot, private config: DiscordBridgeConfig) {
this.parser = new MatrixMessageParser();
}
public async FormatMessage(
msg: IMatrixMessage,
guild: Discord.Guild,
params?: IMatrixMessageProcessorParams,
): Promise<string> {
const opts = this.getParserOpts(msg, guild, params);
return this.parser.FormatMessage(opts, msg);
}
private getParserOpts(
msg: IMatrixMessage,
guild: Discord.Guild,
params?: IMatrixMessageProcessorParams,
): IMatrixMessageParserOpts {
return {
callbacks: this.getParserCallbacks(msg, guild, params),
determineCodeLanguage: this.config.bridge.determineCodeLanguage,
displayname: params ? params.displayname || "" : "",
};
}
private getParserCallbacks(
msg: IMatrixMessage,
guild: Discord.Guild,
params?: IMatrixMessageProcessorParams,
): IMatrixMessageParserCallbacks {
return {