diff --git a/src/discordmessageprocessor.ts b/src/discordmessageprocessor.ts index bddd2cfe748ffcaa9e287a546f64c71dd4315014..8df12739f6b42be3f65b501f2e09a2a842748519 100644 --- a/src/discordmessageprocessor.ts +++ b/src/discordmessageprocessor.ts @@ -150,6 +150,9 @@ export class DiscordMessageProcessor { public InsertChannel(node: IDiscordNode, msg: Discord.Message, html: boolean = false): string { const id = node.id; const channel = msg.guild.channels.get(id); + if (!channel) { + return html ? `<#${escapeHtml(id)}>` : `<#${id}>`; + } const channelStr = escapeHtml(channel ? "#" + channel.name : "#" + id); if (!html) { return channelStr; diff --git a/test/test_discordmessageprocessor.ts b/test/test_discordmessageprocessor.ts index 78f75ae6f8e18a7e8df5217a688caabf942e9de0..96d71c4a29fa1a3816f76edc43debfce3f93fe95 100644 --- a/test/test_discordmessageprocessor.ts +++ b/test/test_discordmessageprocessor.ts @@ -6,6 +6,7 @@ import { MockGuild } from "./mocks/guild"; import { MockMember } from "./mocks/member"; import { MockMessage } from "./mocks/message"; import { MockRole } from "./mocks/role"; +import { MockChannel } from "./mocks/channel"; // we are a test file and thus need those /* tslint:disable:no-unused-expression max-file-line-count no-any */ @@ -262,11 +263,11 @@ describe("DiscordMessageProcessor", () => { const msg = new MockMessage(channel) as any; const content = { id: "123456789" }; let reply = processor.InsertChannel(content, msg); - Chai.assert.equal(reply, "#123456789"); + Chai.assert.equal(reply, "<#123456789>"); reply = processor.InsertChannel(content, msg, true); Chai.assert.equal(reply, - "<a href=\"https://matrix.to/#/#_discord_123_123456789:localhost\">#123456789</a>"); + "<#123456789>"); }); it("processes channels correctly", () => { const processor = new DiscordMessageProcessor(