Skip to content
Extraits de code Groupes Projets
Sélectionner une révision Git
  • 628677fc6fd11b20fdbfb554c2e6b0d15cd3022c
  • develop par défaut protégée
  • upgrade-appservice
  • baguette-custom-fixes
  • fix-discord-reply-edited
  • update-readme-badges
6 résultats

matrixeventprocessor.ts

Blame
  • matrixeventprocessor.ts 5,37 Kio
    import * as Discord from "discord.js";
    import {MessageProcessorOpts, MessageProcessor} from "./messageprocessor";
    import {DiscordBot} from "./bot";
    import {DiscordBridgeConfig} from "./config";
    import * as escapeStringRegexp from "escape-string-regexp";
    import {Util} from "./util";
    import * as path from "path";
    import * as mime from "mime";
    import * as log from "npmlog";
    
    const MaxFileSize = 8000000;
    const MIN_NAME_LENGTH = 2;
    const MAX_NAME_LENGTH = 32;
    const DISCORD_EMOJI_REGEX = /:(\w+):/g;
    
    export class MatrixEventProcessorOpts {
        constructor(
            readonly config: DiscordBridgeConfig,
            readonly bridge: any,
            ) {
    
        }
    }
    
    export class MatrixEventProcessor {
        private config: DiscordBridgeConfig;
        private bridge: any;
    
        constructor (opts: MatrixEventProcessorOpts) {
            this.config = opts.config;
            this.bridge = opts.bridge;
        }
    
        public EventToEmbed(event: any, profile: any|null, channel: Discord.TextChannel): Discord.RichEmbed {
            let body = this.config.bridge.disableDiscordMentions ? event.content.body :
                this.FindMentionsInPlainBody(
                    event.content.body,
                    channel.members.array(),
                );
    
            // Replace @everyone
            if (this.config.bridge.disableEveryoneMention) {
                body = body.replace(new RegExp(`@everyone`, "g"), "@ everyone");
            }
    
            // Replace @here
            if (this.config.bridge.disableHereMention) {
                body = body.replace(new RegExp(`@here`, "g"), "@ here");
            }
    
            // Handle discord custom emoji
            body = this.ReplaceDiscordEmoji(body, channel.guild);
    
            let displayName = event.sender;
            let avatarUrl = undefined;
            if (profile) {
                if (profile.displayname &&
                    profile.displayname.length >= MIN_NAME_LENGTH &&
                    profile.displayname.length <= MAX_NAME_LENGTH) {
                    displayName = profile.displayname;
                }
    
                if (profile.avatar_url) {
                    const mxClient = this.bridge.getClientFactory().getClientAs();
                    avatarUrl = mxClient.mxcUrlToHttp(profile.avatar_url);
                }
                /* See issue #82
                const isMarkdown = (event.content.format === "org.matrix.custom.html");
                if (!isMarkdown) {
                  body = "\\" + body;