Fixed nullref in channel mention resolving for DM channels

This commit is contained in:
RogueException
2016-08-16 20:29:39 -03:00
parent 8ea812cba3
commit 7b130f6528
2 changed files with 15 additions and 16 deletions

View File

@@ -1,5 +1,4 @@
using Discord.API.Rest; using Discord.API.Rest;
using Discord.Rest;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Immutable; using System.Collections.Immutable;

View File

@@ -208,8 +208,6 @@ namespace Discord
{ {
if (mode == ChannelMentionHandling.Ignore) return text; if (mode == ChannelMentionHandling.Ignore) return text;
if (guild.IsAttached) //It's too expensive to do a channel lookup in REST mode
{
return _channelRegex.Replace(text, new MatchEvaluator(e => return _channelRegex.Replace(text, new MatchEvaluator(e =>
{ {
ulong id; ulong id;
@@ -220,19 +218,21 @@ namespace Discord
case ChannelMentionHandling.Remove: case ChannelMentionHandling.Remove:
return ""; return "";
case ChannelMentionHandling.Name: case ChannelMentionHandling.Name:
if (guild != null && guild.IsAttached) //It's too expensive to do a channel lookup in REST mode
{
IGuildChannel channel = null; IGuildChannel channel = null;
channel = guild?.GetChannel(id); channel = guild.GetChannel(id);
if (channel != null) if (channel != null)
return $"#{channel.Name}"; return $"#{channel.Name}";
else else
return $"#deleted-channel"; return $"#deleted-channel";
} }
break;
}
} }
return e.Value; return e.Value;
})); }));
} }
return text;
}
internal static string ResolveRoleMentions(string text, IReadOnlyCollection<IRole> mentions, RoleMentionHandling mode) internal static string ResolveRoleMentions(string text, IReadOnlyCollection<IRole> mentions, RoleMentionHandling mode)
{ {
if (mode == RoleMentionHandling.Ignore) return text; if (mode == RoleMentionHandling.Ignore) return text;