diff --git a/config/config.sample.yaml b/config/config.sample.yaml index 674f815ae3c3e93ab957c63cbe093c23bfeba193..13501eda8afa5cc627152f83ae0cdedf35c0d8e6 100644 --- a/config/config.sample.yaml +++ b/config/config.sample.yaml @@ -29,6 +29,8 @@ bridge: disableReadReceipts: false # Disable Join Leave echos from matrix disableJoinLeaveNotifications: false + # Auto-determine the language of code blocks (this can be CPU-intensive) + determineCodeLanguage: false # Authentication configuration for the discord bot. auth: # This MUST be a string (wrapped in quotes) diff --git a/package-lock.json b/package-lock.json index be240fdcabdc469d416503bc7085b506021c192b..e68d36cb4ddb69847f7a22ea2458a4a783617cb8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1032,11 +1032,12 @@ "integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==" }, "discord-markdown": { - "version": "git://github.com/Sorunome/discord-markdown.git#5086d4ccb10a90bcdc7656606f5b3f5430bffee9", - "from": "git://github.com/Sorunome/discord-markdown.git#5086d4ccb10a90bcdc7656606f5b3f5430bffee9", + "version": "git://github.com/Sorunome/discord-markdown.git#b6e7d67094a846f85ba5b6aa5f0ccf0a6ad02a0b", + "from": "git://github.com/Sorunome/discord-markdown.git#b6e7d67094a846f85ba5b6aa5f0ccf0a6ad02a0b", "requires": { - "highlight.js": "^9.13.1", - "simple-markdown": "^0.4.4" + "escape-html": "^1.0.3", + "highlight.js": "^9.15.9", + "simple-markdown": "^0.5.3" } }, "discord.js": { @@ -1701,9 +1702,9 @@ "dev": true }, "handlebars": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.1.2.tgz", - "integrity": "sha512-nvfrjqvt9xQ8Z/w0ijewdD/vvWDTOweBUm96NTr66Wfvo1mJenBLwcYmPs3TIBP5ruzYGD7Hx/DaM9RmhroGPw==", + "version": "4.7.2", + "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.7.2.tgz", + "integrity": "sha512-4PwqDL2laXtTWZghzzCtunQUTLbo31pcCJrd/B/9JP8XbhVzpS5ZXuKqlOzsd1rtcaLo4KqAn8nl8mkknS4MHw==", "dev": true, "requires": { "neo-async": "^2.6.0", @@ -1772,9 +1773,9 @@ "integrity": "sha1-k0EP0hsAlzUVH4howvJx80J+I/0=" }, "highlight.js": { - "version": "9.15.9", - "resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-9.15.9.tgz", - "integrity": "sha512-M0zZvfLr5p0keDMCAhNBp03XJbKBxUx5AfyfufMdFMEP4N/Xj6dh0IqC75ys7BAzceR34NgcvXjupRVaHBPPVQ==" + "version": "9.18.0", + "resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-9.18.0.tgz", + "integrity": "sha512-A97kI1KAUzKoAiEoaGcf2O9YPS8nbDTCRFokaaeBhnqjQTvbAuAJrQMm21zw8s8xzaMtCQBtgbyGXLGxdxQyqQ==" }, "hosted-git-info": { "version": "2.8.4", @@ -2426,32 +2427,19 @@ } }, "matrix-discord-parser": { - "version": "0.0.3", - "resolved": "https://registry.npmjs.org/matrix-discord-parser/-/matrix-discord-parser-0.0.3.tgz", - "integrity": "sha512-WWDFuL7AjgzIgZXlzXqH2I0yqfy1DMAWDnnHJcGVnooLAMrwTlvKmaYOb5uUURx0NoWJ24vncYizvGeyqlC+Yg==", + "version": "0.0.4-1", + "resolved": "https://registry.npmjs.org/matrix-discord-parser/-/matrix-discord-parser-0.0.4-1.tgz", + "integrity": "sha512-KH/FOpq4Fj8yQ8ECZG8pmzk4XzEq3ENQgiBSd6Nam8pxGS2yKJmPBA6WWctDI+QnV6i+UQlwyxVFXkVdOBBuSQ==", "requires": { - "discord-markdown": "git://github.com/Sorunome/discord-markdown.git#6cd4092e0d2155249782535773196d738861eb09", + "discord-markdown": "git://github.com/Sorunome/discord-markdown.git#b6e7d67094a846f85ba5b6aa5f0ccf0a6ad02a0b", "discord.js": "^11.5.1", "escape-html": "^1.0.3", "escape-string-regexp": "^1.0.5", + "highlight.js": "^9.17.1", "node-html-parser": "^1.1.15", "tslint": "^5.11.0", - "typescript": "^3.1.3" - }, - "dependencies": { - "discord-markdown": { - "version": "git://github.com/Sorunome/discord-markdown.git#6cd4092e0d2155249782535773196d738861eb09", - "from": "git://github.com/Sorunome/discord-markdown.git#6cd4092e0d2155249782535773196d738861eb09", - "requires": { - "highlight.js": "^9.15.9", - "simple-markdown": "^0.5.1" - } - }, - "simple-markdown": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/simple-markdown/-/simple-markdown-0.5.1.tgz", - "integrity": "sha512-sFd1OPwEq0aEk3y0KUAkD0OiakTsYDDcfqga892ZLWWy89LmpJj9ZDU2WOc+C18ej3iNgIi15xU0YKKnAQcuEQ==" - } + "typescript": "^3.1.3", + "unescape-html": "^1.1.0" } }, "media-typer": { @@ -3483,9 +3471,9 @@ "dev": true }, "simple-markdown": { - "version": "0.4.4", - "resolved": "https://registry.npmjs.org/simple-markdown/-/simple-markdown-0.4.4.tgz", - "integrity": "sha512-ZmlNUGR1KI12sPHeQ7dQY1qM5KfOgFqClNNVO8zQ9Pg6u7gHLCPFGD+VC7MCwpGDMd1uw3Bb2TfFfR8d6bB34A==" + "version": "0.5.3", + "resolved": "https://registry.npmjs.org/simple-markdown/-/simple-markdown-0.5.3.tgz", + "integrity": "sha512-nFvw0DTiVHdd7v/f1DyuQ+2b3V3ZXummODZ9z9IO2dBVM+h4Cg5nnfuU43h6DYcsVrHHI1HcMe8t3b/lpAYBIQ==" }, "simple-swizzle": { "version": "0.2.2", @@ -4020,16 +4008,23 @@ "integrity": "sha1-XAgOXWYcu+OCWdLnCjxyU+hziB0=" }, "uglify-js": { - "version": "3.6.0", - "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.6.0.tgz", - "integrity": "sha512-W+jrUHJr3DXKhrsS7NUVxn3zqMOFn0hL/Ei6v0anCIMoKC93TjcflTagwIHLW7SfMFfiQuktQyFVCFHGUE0+yg==", + "version": "3.7.6", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.7.6.tgz", + "integrity": "sha512-yYqjArOYSxvqeeiYH2VGjZOqq6SVmhxzaPjJC1W2F9e+bqvFL9QXQ2osQuKUFjM2hGjKG2YclQnRKWQSt/nOTQ==", "dev": true, "optional": true, "requires": { - "commander": "~2.20.0", + "commander": "~2.20.3", "source-map": "~0.6.1" }, "dependencies": { + "commander": { + "version": "2.20.3", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", + "dev": true, + "optional": true + }, "source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", @@ -4039,6 +4034,11 @@ } } }, + "unescape-html": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/unescape-html/-/unescape-html-1.1.0.tgz", + "integrity": "sha512-O9/yBNqIkArjS597iHez5hAaAdn7b8/230SX8IncgXAX5tWI9XlEQYaz6Qbou0Sloa9n6lx9G5s6hg5qhJyzGg==" + }, "unpipe": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", diff --git a/package.json b/package.json index 1dbba6e3bbfc1d0ad21a4a5be08d8c419968d027..cb266ec73e2cd9713ae74fd0397aa73c5f4db818 100644 --- a/package.json +++ b/package.json @@ -39,13 +39,12 @@ "better-sqlite3": "^5.4.2", "command-line-args": "^4.0.7", "command-line-usage": "^4.1.0", - "discord-markdown": "git://github.com/Sorunome/discord-markdown#5086d4ccb10a90bcdc7656606f5b3f5430bffee9", "discord.js": "^11.5.1", "escape-html": "^1.0.3", "escape-string-regexp": "^1.0.5", "js-yaml": "^3.13.1", "matrix-bot-sdk": "0.4.1", - "matrix-discord-parser": "0.0.3", + "matrix-discord-parser": "0.0.4-1", "mime": "^2.0.1", "node-html-parser": "^1.1.15", "p-queue": "^6.0.1", diff --git a/src/config.ts b/src/config.ts index 505e530a9149bf39c52b0b3eb30f00c6d3df0199..da10149deb8da68d8703901fccce08d9e7bf1977 100644 --- a/src/config.ts +++ b/src/config.ts @@ -93,6 +93,7 @@ class DiscordBridgeConfigBridge { public disableEveryoneMention: boolean = false; public disableHereMention: boolean = false; public disableJoinLeaveNotifications: boolean = false; + public determineCodeLanguage: boolean = false; } export class DiscordBridgeConfigDatabase { diff --git a/src/matrixeventprocessor.ts b/src/matrixeventprocessor.ts index 77a0ac52d558bee3125dbc1081f068385e5158f1..f0f1931286d756997ca26676138cb33f69645221 100644 --- a/src/matrixeventprocessor.ts +++ b/src/matrixeventprocessor.ts @@ -71,7 +71,7 @@ export class MatrixEventProcessor { this.bridge = opts.bridge; this.discord = opts.discord; this.store = opts.store; - this.matrixMsgProcessor = new MatrixMessageProcessor(this.discord); + this.matrixMsgProcessor = new MatrixMessageProcessor(this.discord, this.config); this.mxUserProfileCache = new TimedCache(PROFILE_CACHE_LIFETIME); if (cm) { this.mxCommandHandler = cm; diff --git a/src/matrixmessageprocessor.ts b/src/matrixmessageprocessor.ts index 9a91e5e54e60914e41f738315d632c3bfc99e1fd..eac3d67564db9b156254ad1f19053ea116c73bfd 100644 --- a/src/matrixmessageprocessor.ts +++ b/src/matrixmessageprocessor.ts @@ -20,6 +20,7 @@ import * as Parser from "node-html-parser"; import { Util } from "./util"; import { DiscordBot } from "./bot"; import { MatrixClient } from "matrix-bot-sdk"; +import { DiscordBridgeConfig } from "./config"; import { IMatrixMessageParserCallbacks, IMatrixMessageParserOpts, @@ -38,7 +39,7 @@ export interface IMatrixMessageProcessorParams { export class MatrixMessageProcessor { private listBulletPoints: string[] = ["●", "○", "■", "‣"]; private parser: MatrixMessageParser; - constructor(public bot: DiscordBot) { + constructor(public bot: DiscordBot, private config: DiscordBridgeConfig) { this.parser = new MatrixMessageParser(); } @@ -58,6 +59,7 @@ export class MatrixMessageProcessor { ): IMatrixMessageParserOpts { return { callbacks: this.getParserCallbacks(msg, guild, params), + determineCodeLanguage: this.config.bridge.determineCodeLanguage, displayname: params ? params.displayname || "" : "", }; } diff --git a/src/store.ts b/src/store.ts index 6743c0410fba2c826c09693880ff6576b49c9361..9a637ee9b07fe8b76e986be02b3b00c6406591e0 100644 --- a/src/store.ts +++ b/src/store.ts @@ -46,6 +46,8 @@ export class DiscordStore implements IAppserviceStorageProvider { } else { this.config = configOrFile; } + this.registeredUsers = new Set(); + this.asTxns = new Set(); } get roomStore() { @@ -288,7 +290,7 @@ export class DiscordStore implements IAppserviceStorageProvider { public setTransactionCompleted(transactionId: string) { this.asTxns.add(transactionId); - this.db.Run("INSERT INTO txn_id VALUES ($transactionId)", {transactionId}).catch((err) => { + this.db.Run("INSERT INTO as_txns (txn_id) VALUES ($transactionId)", {transactionId}).catch((err) => { log.warn("Failed to insert txn", err); }); } diff --git a/test/test_matrixmessageprocessor.ts b/test/test_matrixmessageprocessor.ts index a4a7d9194a2f4748cad097d4f384fac45c5a0d40..c4db261becfcdb21468fefe1392619ed612d3e21 100644 --- a/test/test_matrixmessageprocessor.ts +++ b/test/test_matrixmessageprocessor.ts @@ -45,6 +45,12 @@ const bot = { }, } as any; +const config = { + bridge: { + determineCodeLanguage: false, + }, +} as any; + function getPlainMessage(msg: string, msgtype: string = "m.text") { return { body: msg, @@ -63,28 +69,28 @@ function getHtmlMessage(msg: string, msgtype: string = "m.text") { describe("MatrixMessageProcessor", () => { describe("FormatMessage / body / simple", () => { it("leaves blank stuff untouched", async () => { - const mp = new MatrixMessageProcessor(bot); + const mp = new MatrixMessageProcessor(bot, config); const guild = new MockGuild("1234"); const msg = getPlainMessage("hello world!"); const result = await mp.FormatMessage(msg, guild as any); expect(result).is.equal("hello world!"); }); it("escapes simple stuff", async () => { - const mp = new MatrixMessageProcessor(bot); + const mp = new MatrixMessageProcessor(bot, config); const guild = new MockGuild("1234"); const msg = getPlainMessage("hello *world* how __are__ you?"); const result = await mp.FormatMessage(msg, guild as any); expect(result).is.equal("hello \\*world\\* how \\_\\_are\\_\\_ you?"); }); it("escapes more complex stuff", async () => { - const mp = new MatrixMessageProcessor(bot); + const mp = new MatrixMessageProcessor(bot, config); const guild = new MockGuild("1234"); const msg = getPlainMessage("wow \\*this\\* is cool"); const result = await mp.FormatMessage(msg, guild as any); expect(result).is.equal("wow \\\\\\*this\\\\\\* is cool"); }); it("escapes ALL the stuff", async () => { - const mp = new MatrixMessageProcessor(bot); + const mp = new MatrixMessageProcessor(bot, config); const guild = new MockGuild("1234"); const msg = getPlainMessage("\\ * _ ~ ` |"); const result = await mp.FormatMessage(msg, guild as any); @@ -93,56 +99,56 @@ describe("MatrixMessageProcessor", () => { }); describe("FormatMessage / formatted_body / simple", () => { it("leaves blank stuff untouched", async () => { - const mp = new MatrixMessageProcessor(bot); + const mp = new MatrixMessageProcessor(bot, config); const guild = new MockGuild("1234"); const msg = getHtmlMessage("hello world!"); const result = await mp.FormatMessage(msg, guild as any); expect(result).is.equal("hello world!"); }); it("un-escapes simple stuff", async () => { - const mp = new MatrixMessageProcessor(bot); + const mp = new MatrixMessageProcessor(bot, config); const guild = new MockGuild("1234"); const msg = getHtmlMessage("foxes & foxes"); const result = await mp.FormatMessage(msg, guild as any); expect(result).is.equal("foxes & foxes"); }); it("converts italic formatting", async () => { - const mp = new MatrixMessageProcessor(bot); + const mp = new MatrixMessageProcessor(bot, config); const guild = new MockGuild("1234"); const msg = getHtmlMessage("this text is <em>italic</em> and so is <i>this one</i>"); const result = await mp.FormatMessage(msg, guild as any); expect(result).is.equal("this text is *italic* and so is *this one*"); }); it("converts bold formatting", async () => { - const mp = new MatrixMessageProcessor(bot); + const mp = new MatrixMessageProcessor(bot, config); const guild = new MockGuild("1234"); const msg = getHtmlMessage("wow some <b>bold</b> and <strong>more</strong> boldness!"); const result = await mp.FormatMessage(msg, guild as any); expect(result).is.equal("wow some **bold** and **more** boldness!"); }); it("converts underline formatting", async () => { - const mp = new MatrixMessageProcessor(bot); + const mp = new MatrixMessageProcessor(bot, config); const guild = new MockGuild("1234"); const msg = getHtmlMessage("to be <u>underlined</u> or not to be?"); const result = await mp.FormatMessage(msg, guild as any); expect(result).is.equal("to be __underlined__ or not to be?"); }); it("converts strike formatting", async () => { - const mp = new MatrixMessageProcessor(bot); + const mp = new MatrixMessageProcessor(bot, config); const guild = new MockGuild("1234"); const msg = getHtmlMessage("does <del>this text</del> exist?"); const result = await mp.FormatMessage(msg, guild as any); expect(result).is.equal("does ~~this text~~ exist?"); }); it("converts code", async () => { - const mp = new MatrixMessageProcessor(bot); + const mp = new MatrixMessageProcessor(bot, config); const guild = new MockGuild("1234"); const msg = getHtmlMessage("WOW this is <code>some awesome</code> code"); const result = await mp.FormatMessage(msg, guild as any); expect(result).is.equal("WOW this is `some awesome` code"); }); it("converts multiline-code", async () => { - const mp = new MatrixMessageProcessor(bot); + const mp = new MatrixMessageProcessor(bot, config); const guild = new MockGuild("1234"); const msg = getHtmlMessage("<p>here</p><pre><code>is\ncode\n</code></pre><p>yay</p>"); const result = await mp.FormatMessage(msg, guild as any); @@ -151,7 +157,7 @@ describe("MatrixMessageProcessor", () => { }); describe("FormatMessage / formatted_body / discord", () => { it("Parses user pills", async () => { - const mp = new MatrixMessageProcessor(bot); + const mp = new MatrixMessageProcessor(bot, config); const guild = new MockGuild("1234"); const member = new MockMember("12345", "TestUsername", guild); guild.members.set("12345", member); @@ -160,7 +166,7 @@ describe("MatrixMessageProcessor", () => { expect(result).is.equal("<@12345>"); }); it("Ignores invalid user pills", async () => { - const mp = new MatrixMessageProcessor(bot); + const mp = new MatrixMessageProcessor(bot, config); const guild = new MockGuild("1234"); const member = new MockMember("12345", "TestUsername", guild); guild.members.set("12345", member); @@ -169,7 +175,7 @@ describe("MatrixMessageProcessor", () => { expect(result).is.equal("[TestUsername](https://matrix.to/#/@_discord_789:localhost)"); }); it("Parses channel pills", async () => { - const mp = new MatrixMessageProcessor(bot); + const mp = new MatrixMessageProcessor(bot, config); const guild = new MockGuild("1234"); const channel = new MockChannel("12345", guild, "text", "SomeChannel"); guild.channels.set("12345", channel as any); @@ -179,7 +185,7 @@ describe("MatrixMessageProcessor", () => { expect(result).is.equal("<#12345>"); }); it("Handles invalid channel pills", async () => { - const mp = new MatrixMessageProcessor(bot); + const mp = new MatrixMessageProcessor(bot, config); const guild = new MockGuild("1234"); const channel = new MockChannel("12345", guild, "text", "SomeChannel"); guild.channels.set("12345", channel as any); @@ -188,14 +194,14 @@ describe("MatrixMessageProcessor", () => { expect(result).is.equal("[#SomeChannel](https://matrix.to/#/#_discord_1234_789:localhost)"); }); it("Handles external channel pills", async () => { - const mp = new MatrixMessageProcessor(bot); + const mp = new MatrixMessageProcessor(bot, config); const guild = new MockGuild("1234"); const msg = getHtmlMessage("<a href=\"https://matrix.to/#/#matrix:matrix.org\">#SomeChannel</a>"); const result = await mp.FormatMessage(msg, guild as any); expect(result).is.equal("[#SomeChannel](https://matrix.to/#/#matrix:matrix.org)"); }); it("Handles external channel pills of rooms that are actually bridged", async () => { - const mp = new MatrixMessageProcessor(bot); + const mp = new MatrixMessageProcessor(bot, config); const guild = new MockGuild("1234"); const msg = getHtmlMessage("<a href=\"https://matrix.to/#/#matrix:matrix.org\">#SomeChannel</a>"); @@ -211,28 +217,28 @@ describe("MatrixMessageProcessor", () => { expect(result).is.equal("<#1234>"); }); it("Ignores links without href", async () => { - const mp = new MatrixMessageProcessor(bot); + const mp = new MatrixMessageProcessor(bot, config); const guild = new MockGuild("1234"); const msg = getHtmlMessage("<a><em>yay?</em></a>"); const result = await mp.FormatMessage(msg, guild as any); expect(result).is.equal("*yay?*"); }); it("Ignores links with non-matrix href", async () => { - const mp = new MatrixMessageProcessor(bot); + const mp = new MatrixMessageProcessor(bot, config); const guild = new MockGuild("1234"); const msg = getHtmlMessage("<a href=\"http://example.com\"><em>yay?</em></a>"); const result = await mp.FormatMessage(msg, guild as any); expect(result).is.equal("[*yay?*](http://example.com)"); }); it("Handles spoilers", async () => { - const mp = new MatrixMessageProcessor(bot); + const mp = new MatrixMessageProcessor(bot, config); const guild = new MockGuild("1234"); const msg = getHtmlMessage("<span data-mx-spoiler>foxies</span>"); const result = await mp.FormatMessage(msg, guild as any); expect(result).is.equal("||foxies||"); }); it("Handles spoilers with reason", async () => { - const mp = new MatrixMessageProcessor(bot); + const mp = new MatrixMessageProcessor(bot, config); const guild = new MockGuild("1234"); const msg = getHtmlMessage("<span data-mx-spoiler=\"floof\">foxies</span>"); const result = await mp.FormatMessage(msg, guild as any); @@ -241,7 +247,7 @@ describe("MatrixMessageProcessor", () => { }); describe("FormatMessage / formatted_body / emoji", () => { it("Inserts emoji by name", async () => { - const mp = new MatrixMessageProcessor(bot); + const mp = new MatrixMessageProcessor(bot, config); const guild = new MockGuild("1234"); const emoji = new MockEmoji("123456", "test_emoji"); guild.emojis.set("123456", emoji); @@ -250,7 +256,7 @@ describe("MatrixMessageProcessor", () => { expect(result).is.equal("<:test_emoji:123456>"); }); it("Inserts emojis by mxc url", async () => { - const mp = new MatrixMessageProcessor(bot); + const mp = new MatrixMessageProcessor(bot, config); const guild = new MockGuild("1234"); const emoji = new MockEmoji("123456", "test_emoji"); guild.emojis.set("123456", emoji); @@ -259,7 +265,7 @@ describe("MatrixMessageProcessor", () => { expect(result).is.equal("<:test_emoji:123456>"); }); it("parses unknown mxc urls", async () => { - const mp = new MatrixMessageProcessor(bot); + const mp = new MatrixMessageProcessor(bot, config); const guild = new MockGuild("1234"); const emoji = new MockEmoji("123456", "test_emoji"); guild.emojis.set("123456", emoji); @@ -268,7 +274,7 @@ describe("MatrixMessageProcessor", () => { expect(result).is.equal("[yay](mxc://unreal_emote:localhost)"); }); it("ignores with no alt / title, too", async () => { - const mp = new MatrixMessageProcessor(bot); + const mp = new MatrixMessageProcessor(bot, config); const guild = new MockGuild("1234"); const emoji = new MockEmoji("123456", "test_emoji"); guild.emojis.set("123456", emoji); @@ -320,21 +326,21 @@ describe("MatrixMessageProcessor", () => { const ROOM_NOTIFICATION_LEVEL = 50; it("escapes @everyone", async () => { - const mp = new MatrixMessageProcessor(bot); + const mp = new MatrixMessageProcessor(bot, config); const guild = new MockGuild("1234"); const msg = getPlainMessage("hey @everyone"); const result = await mp.FormatMessage(msg, guild as any); expect(result).is.equal("hey @\u200Beveryone"); }); it("escapes @here", async () => { - const mp = new MatrixMessageProcessor(bot); + const mp = new MatrixMessageProcessor(bot, config); const guild = new MockGuild("1234"); const msg = getPlainMessage("hey @here"); const result = await mp.FormatMessage(msg, guild as any); expect(result).is.equal("hey @\u200Bhere"); }); it("converts @room to @here, if sufficient power", async () => { - const mp = new MatrixMessageProcessor(bot); + const mp = new MatrixMessageProcessor(bot, config); const guild = new MockGuild("1234"); const msg = getPlainMessage("hey @room"); let params = { @@ -357,7 +363,7 @@ describe("MatrixMessageProcessor", () => { expect(result).is.equal("hey @here"); }); it("ignores @room to @here conversion, if insufficient power", async () => { - const mp = new MatrixMessageProcessor(bot); + const mp = new MatrixMessageProcessor(bot, config); const guild = new MockGuild("1234"); const msg = getPlainMessage("hey @room"); let params = { @@ -380,7 +386,7 @@ describe("MatrixMessageProcessor", () => { expect(result).is.equal("hey @room"); }); it("handles /me for normal names", async () => { - const mp = new MatrixMessageProcessor(bot); + const mp = new MatrixMessageProcessor(bot, config); const guild = new MockGuild("1234"); const msg = getPlainMessage("floofs", "m.emote"); const params = { @@ -390,7 +396,7 @@ describe("MatrixMessageProcessor", () => { expect(result).is.equal("_fox floofs_"); }); it("handles /me for short names", async () => { - const mp = new MatrixMessageProcessor(bot); + const mp = new MatrixMessageProcessor(bot, config); const guild = new MockGuild("1234"); const msg = getPlainMessage("floofs", "m.emote"); const params = { @@ -400,7 +406,7 @@ describe("MatrixMessageProcessor", () => { expect(result).is.equal("_floofs_"); }); it("handles /me for long names", async () => { - const mp = new MatrixMessageProcessor(bot); + const mp = new MatrixMessageProcessor(bot, config); const guild = new MockGuild("1234"); const msg = getPlainMessage("floofs", "m.emote"); const params = { @@ -410,7 +416,7 @@ describe("MatrixMessageProcessor", () => { expect(result).is.equal("_floofs_"); }); it("discord escapes nicks in /me", async () => { - const mp = new MatrixMessageProcessor(bot); + const mp = new MatrixMessageProcessor(bot, config); const guild = new MockGuild("1234"); const msg = getPlainMessage("floofs", "m.emote"); const params = {