diff --git a/lib/bot.js b/lib/bot.js index c943d674..9c743ec5 100644 --- a/lib/bot.js +++ b/lib/bot.js @@ -139,7 +139,8 @@ class Bot { .replace(/\n|\r\n|\r/g, ' ') .replace(/<#(\d+)>/g, (match, channelId) => { const channel = this.discord.channels.get(channelId); - return `#${channel.name}`; + if (channel) return `#${channel.name}`; + return '#deleted-channel'; }) .replace(/<(:\w+:)\d+>/g, (match, emoteName) => emoteName); } diff --git a/test/bot.test.js b/test/bot.test.js index 4162b7c1..31e23e71 100644 --- a/test/bot.test.js +++ b/test/bot.test.js @@ -249,6 +249,30 @@ describe('Bot', function () { .should.have.been.calledWith('#irc', expected); }); + it('should use #deleted-channel when referenced channel fails to exist', function () { + const text = '<#1235>'; + const guild = createGuildStub(); + const message = { + content: text, + mentions: { users: [] }, + channel: { + name: 'discord' + }, + author: { + username: 'test', + id: 'not bot id' + }, + guild + }; + + // Discord displays "#deleted-channel" if channel doesn't exist (e.g. <#1235>) + // Wrap it in colors: + const expected = `<\u000312${message.author.username}\u000f> #deleted-channel`; + this.bot.sendToIRC(message); + ClientStub.prototype.say + .should.have.been.calledWith('#irc', expected); + }); + it('should convert user mentions from discord', function () { const guild = createGuildStub(); const message = { diff --git a/test/stubs/discord-stub.js b/test/stubs/discord-stub.js index 12145fa5..e351dc9a 100644 --- a/test/stubs/discord-stub.js +++ b/test/stubs/discord-stub.js @@ -23,6 +23,7 @@ export default function createDiscordStub(sendMessageStub, findUserStub) { getChannel(key, value) { if (key === 'name' && value !== 'discord') return null; + if (key !== '1234' && value === undefined) return null; return { name: 'discord', id: 1234,