Restrict typereaders to using the cache

This commit is contained in:
RogueException
2016-10-08 18:41:55 -03:00
parent 21c38412ad
commit 8ab675e775
2 changed files with 9 additions and 9 deletions

View File

@@ -14,16 +14,16 @@ namespace Discord.Commands
if (context.Guild != null)
{
var results = new Dictionary<ulong, TypeReaderValue>();
var channels = await context.Guild.GetChannelsAsync().ConfigureAwait(false);
var channels = await context.Guild.GetChannelsAsync(CacheMode.CacheOnly).ConfigureAwait(false);
ulong id;
//By Mention (1.0)
if (MentionUtils.TryParseChannel(input, out id))
AddResult(results, await context.Guild.GetChannelAsync(id).ConfigureAwait(false) as T, 1.00f);
AddResult(results, await context.Guild.GetChannelAsync(id, CacheMode.CacheOnly).ConfigureAwait(false) as T, 1.00f);
//By Id (0.9)
if (ulong.TryParse(input, NumberStyles.None, CultureInfo.InvariantCulture, out id))
AddResult(results, await context.Guild.GetChannelAsync(id).ConfigureAwait(false) as T, 0.90f);
AddResult(results, await context.Guild.GetChannelAsync(id, CacheMode.CacheOnly).ConfigureAwait(false) as T, 0.90f);
//By Name (0.7-0.8)
foreach (var channel in channels.Where(x => string.Equals(input, x.Name, StringComparison.OrdinalIgnoreCase)))

View File

@@ -13,29 +13,29 @@ namespace Discord.Commands
public override async Task<TypeReaderResult> Read(CommandContext context, string input)
{
var results = new Dictionary<ulong, TypeReaderValue>();
IReadOnlyCollection<IUser> channelUsers = (await context.Channel.GetUsersAsync().Flatten().ConfigureAwait(false)).ToArray(); //TODO: must be a better way?
IReadOnlyCollection<IUser> channelUsers = (await context.Channel.GetUsersAsync(CacheMode.CacheOnly).Flatten().ConfigureAwait(false)).ToArray(); //TODO: must be a better way?
IReadOnlyCollection<IGuildUser> guildUsers = null;
ulong id;
if (context.Guild != null)
guildUsers = await context.Guild.GetUsersAsync().ConfigureAwait(false);
guildUsers = await context.Guild.GetUsersAsync(CacheMode.CacheOnly).ConfigureAwait(false);
//By Mention (1.0)
if (MentionUtils.TryParseUser(input, out id))
{
if (context.Guild != null)
AddResult(results, await context.Guild.GetUserAsync(id).ConfigureAwait(false) as T, 1.00f);
AddResult(results, await context.Guild.GetUserAsync(id, CacheMode.CacheOnly).ConfigureAwait(false) as T, 1.00f);
else
AddResult(results, await context.Channel.GetUserAsync(id).ConfigureAwait(false) as T, 1.00f);
AddResult(results, await context.Channel.GetUserAsync(id, CacheMode.CacheOnly).ConfigureAwait(false) as T, 1.00f);
}
//By Id (0.9)
if (ulong.TryParse(input, NumberStyles.None, CultureInfo.InvariantCulture, out id))
{
if (context.Guild != null)
AddResult(results, await context.Guild.GetUserAsync(id).ConfigureAwait(false) as T, 0.90f);
AddResult(results, await context.Guild.GetUserAsync(id, CacheMode.CacheOnly).ConfigureAwait(false) as T, 0.90f);
else
AddResult(results, await context.Channel.GetUserAsync(id).ConfigureAwait(false) as T, 0.90f);
AddResult(results, await context.Channel.GetUserAsync(id, CacheMode.CacheOnly).ConfigureAwait(false) as T, 0.90f);
}
//By Username + Discriminator (0.7-0.85)