Dont fail cleanmentions if a message contains a very large mention id
This commit is contained in:
@@ -66,7 +66,7 @@ namespace Discord.API.Converters
|
|||||||
reader.Read();
|
reader.Read();
|
||||||
while (reader.TokenType != JsonToken.EndArray)
|
while (reader.TokenType != JsonToken.EndArray)
|
||||||
{
|
{
|
||||||
result.Add(((string)reader.Value).ToId());
|
result.Add(((string)reader.Value).TryToId());
|
||||||
reader.Read();
|
reader.Read();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ namespace Discord
|
|||||||
|
|
||||||
public sealed class Message
|
public sealed class Message
|
||||||
{
|
{
|
||||||
private static readonly Regex _userRegex = new Regex(@"<@([0-9]+)>", RegexOptions.Compiled);
|
private static readonly Regex _userRegex = new Regex(@"<@[0-9]+>", RegexOptions.Compiled);
|
||||||
private static readonly Regex _channelRegex = new Regex(@"<#([0-9]+)>", RegexOptions.Compiled);
|
private static readonly Regex _channelRegex = new Regex(@"<#[0-9]+>", RegexOptions.Compiled);
|
||||||
private static readonly Regex _roleRegex = new Regex(@"@everyone", RegexOptions.Compiled);
|
private static readonly Regex _roleRegex = new Regex(@"@everyone", RegexOptions.Compiled);
|
||||||
private static readonly Attachment[] _initialAttachments = new Attachment[0];
|
private static readonly Attachment[] _initialAttachments = new Attachment[0];
|
||||||
private static readonly Embed[] _initialEmbeds = new Embed[0];
|
private static readonly Embed[] _initialEmbeds = new Embed[0];
|
||||||
@@ -32,16 +32,18 @@ namespace Discord
|
|||||||
{
|
{
|
||||||
return _userRegex.Replace(text, new MatchEvaluator(e =>
|
return _userRegex.Replace(text, new MatchEvaluator(e =>
|
||||||
{
|
{
|
||||||
var id = e.Value.Substring(2, e.Value.Length - 3).ToId();
|
ulong id;
|
||||||
var user = channel.GetUser(id);
|
if (e.Value.Substring(2, e.Value.Length - 3).TryToId(out id))
|
||||||
if (user != null)
|
|
||||||
{
|
{
|
||||||
if (users != null)
|
var user = channel.GetUser(id);
|
||||||
users.Add(user);
|
if (user != null)
|
||||||
return '@' + user.Name;
|
{
|
||||||
}
|
if (users != null)
|
||||||
else //User not found
|
users.Add(user);
|
||||||
return '@' + e.Value;
|
return '@' + user.Name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return e.Value; //User not found or parse failed
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
internal static string CleanChannelMentions(Channel channel, string text, List<Channel> channels = null)
|
internal static string CleanChannelMentions(Channel channel, string text, List<Channel> channels = null)
|
||||||
@@ -51,16 +53,18 @@ namespace Discord
|
|||||||
|
|
||||||
return _channelRegex.Replace(text, new MatchEvaluator(e =>
|
return _channelRegex.Replace(text, new MatchEvaluator(e =>
|
||||||
{
|
{
|
||||||
var id = e.Value.Substring(2, e.Value.Length - 3).ToId();
|
ulong id;
|
||||||
var mentionedChannel = server.GetChannel(id);
|
if (e.Value.Substring(2, e.Value.Length - 3).TryToId(out id))
|
||||||
if (mentionedChannel != null && mentionedChannel.Server.Id == server.Id)
|
|
||||||
{
|
{
|
||||||
if (channels != null)
|
var mentionedChannel = server.GetChannel(id);
|
||||||
channels.Add(mentionedChannel);
|
if (mentionedChannel != null && mentionedChannel.Server.Id == server.Id)
|
||||||
return '#' + mentionedChannel.Name;
|
{
|
||||||
|
if (channels != null)
|
||||||
|
channels.Add(mentionedChannel);
|
||||||
|
return '#' + mentionedChannel.Name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else //Channel not found
|
return e.Value; //Channel not found or parse failed
|
||||||
return '#' + e.Value;
|
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
/*internal static string CleanRoleMentions(User user, Channel channel, string text, List<Role> roles = null)
|
/*internal static string CleanRoleMentions(User user, Channel channel, string text, List<Role> roles = null)
|
||||||
|
|||||||
Reference in New Issue
Block a user