Browse Source

Don't crash when user/channel mentions are received in a PM

tags/docs-0.9
RogueException 9 years ago
parent
commit
acc192c689
1 changed files with 11 additions and 8 deletions
  1. +11
    -8
      src/Discord.Net/Helpers/Mention.cs

+ 11
- 8
src/Discord.Net/Helpers/Mention.cs View File

@@ -24,21 +24,24 @@ namespace Discord
text = _userRegex.Replace(text, new MatchEvaluator(e =>
{
string id = e.Value.Substring(2, e.Value.Length - 3);
var user = client.Users[id, server.Id];
var user = client.Users[id, server?.Id];
if (user != null)
return '@' + user.Name;
else //User not found
return '@' + e.Value;
}));
text = _channelRegex.Replace(text, new MatchEvaluator(e =>
if (server != null)
{
string id = e.Value.Substring(2, e.Value.Length - 3);
var channel = client.Channels[id];
if (channel != null && channel.Server.Id == server.Id)
return '#' + channel.Name;
else //Channel not found
text = _channelRegex.Replace(text, new MatchEvaluator(e =>
{
string id = e.Value.Substring(2, e.Value.Length - 3);
var channel = client.Channels[id];
if (channel != null && channel.Server.Id == server.Id)
return '#' + channel.Name;
else //Channel not found
return '#' + e.Value;
}));
}));
}
return text;
}



Loading…
Cancel
Save