Skip to content
Extraits de code Groupes Projets
Sélectionner une révision Git
  • 4ffd294ab1110729625b1898193c5b66c9777f91
  • develop par défaut
  • renovate/configure
  • rebase-v4
  • cherry-pick-moise protégée
5 résultats

matrixmessageprocessor.ts

Blame
  • 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 {