Fixed User TypeReader not resolving in DMs

This commit is contained in:
RogueException
2016-06-29 05:27:18 -03:00
parent 142e8484ea
commit 5c5a9c8d6f

View File

@@ -9,16 +9,13 @@ namespace Discord.Commands
{
public override async Task<TypeReaderResult> Read(IMessage context, string input)
{
IGuildChannel guildChannel = context.Channel as IGuildChannel;
IUser result = null;
if (guildChannel != null)
{
//By Id
ulong id;
if (MentionUtils.TryParseUser(input, out id) || ulong.TryParse(input, out id))
{
var user = await guildChannel.Guild.GetUserAsync(id).ConfigureAwait(false);
var user = await context.Channel.GetUserAsync(id).ConfigureAwait(false);
if (user != null)
result = user;
}
@@ -33,7 +30,7 @@ namespace Discord.Commands
ushort discriminator;
if (ushort.TryParse(input.Substring(index + 1), out discriminator))
{
var users = await guildChannel.Guild.GetUsersAsync().ConfigureAwait(false);
var users = await context.Channel.GetUsersAsync().ConfigureAwait(false);
result = users.Where(x =>
x.DiscriminatorValue == discriminator &&
string.Equals(username, x.Username, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
@@ -44,14 +41,13 @@ namespace Discord.Commands
//By Username
if (result == null)
{
var users = await guildChannel.Guild.GetUsersAsync().ConfigureAwait(false);
var users = await context.Channel.GetUsersAsync().ConfigureAwait(false);
var filteredUsers = users.Where(x => string.Equals(input, x.Username, StringComparison.OrdinalIgnoreCase)).ToArray();
if (filteredUsers.Length > 1)
return TypeReaderResult.FromError(CommandError.MultipleMatches, "Multiple users found.");
else if (filteredUsers.Length == 1)
result = filteredUsers[0];
}
}
if (result == null)
return TypeReaderResult.FromError(CommandError.ObjectNotFound, "User not found.");