Skip to content
Extraits de code Groupes Projets
Non vérifiée Valider 7e93615b rédigé par Sorunome's avatar Sorunome
Parcourir les fichiers

remove unneeded config options

parent 27c3adf6
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -19,20 +19,11 @@ bridge: ...@@ -19,20 +19,11 @@ bridge:
disablePresence: false disablePresence: false
# Disable sending typing notifications when somebody on Discord types. # Disable sending typing notifications when somebody on Discord types.
disableTypingNotifications: false disableTypingNotifications: false
# Disable parsing discord usernames out of matrix messages so
# that it highlights discord users.
# WARNING: Not always 100% accurate, but close enough usually.
disableDiscordMentions: false
# Disable deleting messages on Discord if a message is redacted on Matrix. # Disable deleting messages on Discord if a message is redacted on Matrix.
disableDeletionForwarding: false disableDeletionForwarding: false
# Enable users to bridge rooms using !discord commands. See # Enable users to bridge rooms using !discord commands. See
# https://t2bot.io/discord for instructions. # https://t2bot.io/discord for instructions.
enableSelfServiceBridging: false enableSelfServiceBridging: false
# For both below, a space is inserted after @ to stop the mentions working.
# Disable relaying @everyone to Discord. Non-puppeted users can abuse this.
disableEveryoneMention: false
# Disable relaying @here to Discord. Non-puppeted users can abuse this.
disableHereMention: false
# Authentication configuration for the discord bot. # Authentication configuration for the discord bot.
auth: auth:
clientID: "12345" clientID: "12345"
......
...@@ -16,16 +16,10 @@ properties: ...@@ -16,16 +16,10 @@ properties:
type: "boolean" type: "boolean"
disableTypingNotifications: disableTypingNotifications:
type: "boolean" type: "boolean"
disableDiscordMentions:
type: "boolean"
disableDeletionForwarding: disableDeletionForwarding:
type: "boolean" type: "boolean"
enableSelfServiceBridging: enableSelfServiceBridging:
type: "boolean" type: "boolean"
disableEveryoneMention:
type: "boolean"
disableHereMention:
type: "boolean"
auth: auth:
type: "object" type: "object"
required: ["botToken", "clientID"] required: ["botToken", "clientID"]
......
...@@ -8,7 +8,7 @@ import * as mime from "mime"; ...@@ -8,7 +8,7 @@ import * as mime from "mime";
import { MatrixUser, Bridge } from "matrix-appservice-bridge"; import { MatrixUser, Bridge } from "matrix-appservice-bridge";
import { Client as MatrixClient } from "matrix-js-sdk"; import { Client as MatrixClient } from "matrix-js-sdk";
import { IMatrixEvent, IMatrixEventContent, IMatrixMessage } from "./matrixtypes"; import { IMatrixEvent, IMatrixEventContent, IMatrixMessage } from "./matrixtypes";
import { MatrixMessageProcessor, MatrixMessageProcessorOpts } from "./matrixmessageprocessor"; import { MatrixMessageProcessor } from "./matrixmessageprocessor";
import { Log } from "./log"; import { Log } from "./log";
const log = new Log("MatrixEventProcessor"); const log = new Log("MatrixEventProcessor");
...@@ -44,13 +44,7 @@ export class MatrixEventProcessor { ...@@ -44,13 +44,7 @@ export class MatrixEventProcessor {
this.config = opts.config; this.config = opts.config;
this.bridge = opts.bridge; this.bridge = opts.bridge;
this.discord = opts.discord; this.discord = opts.discord;
this.matrixMsgProcessor = new MatrixMessageProcessor( this.matrixMsgProcessor = new MatrixMessageProcessor(this.discord);
this.discord,
new MatrixMessageProcessorOpts(
this.config.bridge.disableEveryoneMention,
this.config.bridge.disableHereMention,
),
);
} }
public StateEventToMessage(event: IMatrixEvent, channel: Discord.TextChannel): string | undefined { public StateEventToMessage(event: IMatrixEvent, channel: Discord.TextChannel): string | undefined {
......
...@@ -8,15 +8,11 @@ const MIN_NAME_LENGTH = 2; ...@@ -8,15 +8,11 @@ const MIN_NAME_LENGTH = 2;
const MAX_NAME_LENGTH = 32; const MAX_NAME_LENGTH = 32;
const MATRIX_TO_LINK = "https://matrix.to/#/"; const MATRIX_TO_LINK = "https://matrix.to/#/";
export class MatrixMessageProcessorOpts {
constructor(readonly disableEveryone: boolean = true, readonly disableHere: boolean = true) { }
}
export class MatrixMessageProcessor { export class MatrixMessageProcessor {
private guild: Discord.Guild; private guild: Discord.Guild;
private listDepth: number = 0; private listDepth: number = 0;
private listBulletPoints: string[] = ["", "", "", ""]; private listBulletPoints: string[] = ["", "", "", ""];
constructor(public bot: DiscordBot, public opts: MatrixMessageProcessorOpts) { } constructor(public bot: DiscordBot) { }
public async FormatMessage( public async FormatMessage(
msg: IMatrixMessage, msg: IMatrixMessage,
guild: Discord.Guild, guild: Discord.Guild,
...@@ -54,12 +50,10 @@ export class MatrixMessageProcessor { ...@@ -54,12 +50,10 @@ export class MatrixMessageProcessor {
} }
private escapeDiscord(msg: string): string { private escapeDiscord(msg: string): string {
if (this.opts.disableEveryone) { // \u200B is the zero-width space --> they still look the same but don't mention
msg = msg.replace(/@everyone/g, "@ everyone"); msg = msg.replace(/@everyone/g, "@\u200Beveryone");
} msg = msg.replace(/@here/g, "@\u200Bhere");
if (this.opts.disableHere) {
msg = msg.replace(/@here/g, "@ here");
}
msg = msg.replace(/@room/g, "@here"); msg = msg.replace(/@room/g, "@here");
const escapeChars = ["\\", "*", "_", "~", "`"]; const escapeChars = ["\\", "*", "_", "~", "`"];
escapeChars.forEach((char) => { escapeChars.forEach((char) => {
......
...@@ -59,11 +59,7 @@ const mxClient = { ...@@ -59,11 +59,7 @@ const mxClient = {
}, },
}; };
function createMatrixEventProcessor( function createMatrixEventProcessor(): MatrixEventProcessor {
disableMentions: boolean = false,
disableEveryone = false,
disableHere = false,
): MatrixEventProcessor {
const bridge = { const bridge = {
getBot: () => { getBot: () => {
return { return {
...@@ -134,9 +130,6 @@ function createMatrixEventProcessor( ...@@ -134,9 +130,6 @@ function createMatrixEventProcessor(
}, },
}; };
const config = new DiscordBridgeConfig(); const config = new DiscordBridgeConfig();
config.bridge.disableDiscordMentions = disableMentions;
config.bridge.disableEveryoneMention = disableEveryone;
config.bridge.disableHereMention = disableHere;
const Util = Object.assign(require("../src/util").Util, { const Util = Object.assign(require("../src/util").Util, {
DownloadFile: (name: string) => { DownloadFile: (name: string) => {
...@@ -375,26 +368,26 @@ describe("MatrixEventProcessor", () => { ...@@ -375,26 +368,26 @@ describe("MatrixEventProcessor", () => {
Chai.assert.equal(author!.url, "https://matrix.to/#/@test:localhost"); Chai.assert.equal(author!.url, "https://matrix.to/#/@test:localhost");
}); });
it("Should remove everyone mentions if configured.", async () => { it("Should remove everyone mentions.", async () => {
const processor = createMatrixEventProcessor(false, true); const processor = createMatrixEventProcessor();
const embeds = await processor.EventToEmbed({ const embeds = await processor.EventToEmbed({
content: { content: {
body: "@everyone Hello!", body: "@everyone Hello!",
}, },
sender: "@test:localhost", sender: "@test:localhost",
} as IMatrixEvent, mockChannel as any); } as IMatrixEvent, mockChannel as any);
Chai.assert.equal(embeds.messageEmbed.description, "@ everyone Hello!"); Chai.assert.equal(embeds.messageEmbed.description, "@\u200Beveryone Hello!");
}); });
it("Should remove here mentions if configured.", async () => { it("Should remove here mentions.", async () => {
const processor = createMatrixEventProcessor(false, false, true); const processor = createMatrixEventProcessor();
const embeds = await processor.EventToEmbed({ const embeds = await processor.EventToEmbed({
content: { content: {
body: "@here Hello!", body: "@here Hello!",
}, },
sender: "@test:localhost", sender: "@test:localhost",
} as IMatrixEvent, mockChannel as any); } as IMatrixEvent, mockChannel as any);
Chai.assert.equal(embeds.messageEmbed.description, "@ here Hello!"); Chai.assert.equal(embeds.messageEmbed.description, "@\u200Bhere Hello!");
}); });
it("Should replace /me with * displayname, and italicize message", async () => { it("Should replace /me with * displayname, and italicize message", async () => {
......
Ce diff est replié.
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