Make the bot not crash when a channel mentioned by ID fails to exist #201
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
If a channel is referenced in Discord, e.g.
<#1234>
, and the referenced channel does not exist, the bot seems to crash. This commit fixes it to replace this with '#deleted-channel', as Discord does on that side of the bridge.Present behavior
Writing
#blah
,<#test>
and<#1234>
into IRC causes the bot to show (in Discord):and then writing the same into the Discord channel causes (in IRC):
The crash produced:
The new test (and stubbing behavior) I add with this patch fails on master as follows:
Modified behavior
With the change, it only returns the channel's name where the channel is truthy. (I'm not very acquainted with modern techniques so this might not be the best way to do it? It seems to be
undefined
as returned bythis.discord.channels.get(channelId)
butnull
as returned by the stub, so checkingchannel === undefined
didn't catch that.)Otherwise, it returns
#deleted-channel
(and so writes that into the IRC channel), mirroring the behavior seen in Discord for such invalid channel IDs. This doesn't break any other tests (at least not on my system). The&& value == undefined
condition is to check for when a second parameter isn't given – I wasn't sure whether to use&& !value
or something else instead.