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

This commit is contained in:
RogueException
2015-11-01 23:29:18 -04:00
parent 50d8d76e73
commit acc192c689

View File

@@ -24,12 +24,14 @@ 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;
}));
if (server != null)
{
text = _channelRegex.Replace(text, new MatchEvaluator(e =>
{
string id = e.Value.Substring(2, e.Value.Length - 3);
@@ -39,6 +41,7 @@ namespace Discord
else //Channel not found
return '#' + e.Value;
}));
}
return text;
}