diff --git a/ASFFreeGames/Commands/FreeGamesCommand.cs b/ASFFreeGames/Commands/FreeGamesCommand.cs index 0396f60..8805a15 100644 --- a/ASFFreeGames/Commands/FreeGamesCommand.cs +++ b/ASFFreeGames/Commands/FreeGamesCommand.cs @@ -156,9 +156,18 @@ public void Dispose() { private async ValueTask HandleInternalCollectCommand(Bot? bot, string[] args, CancellationToken cancellationToken) { Dictionary botMap = Context.Bots.ToDictionary(static b => b.BotName.Trim(), static b => b, StringComparer.InvariantCultureIgnoreCase); - Bot[] bots = args.Skip(2).Select(botName => botMap.GetValueOrDefault(botName.Trim())).Where(static b => b is not null).ToArray()!; + List bots = []; - if (bots.Length == 0) { + for (int i = 2; i < args.Length; i++) { + string botName = args[i].Trim(); + + // ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract + if (botMap.TryGetValue(botName, out Bot? savedBot) && savedBot is not null) { + bots.Add(savedBot); + } + } + + if (bots.Count == 0) { if (bot is null) { return null; } @@ -168,7 +177,7 @@ public void Dispose() { int collected = await CollectGames(bots, ECollectGameRequestSource.Scheduled, cancellationToken).ConfigureAwait(false); - return FormatBotResponse(bot, $"Collected a total of {collected} free game(s)" + (bots.Length > 1 ? $" on {bots.Length} bots" : $" on {bots.FirstOrDefault()?.BotName}")); + return FormatBotResponse(bot, $"Collected a total of {collected} free game(s)" + (bots.Count > 1 ? $" on {bots.Count} bots" : $" on {bots.FirstOrDefault()?.BotName}")); } private async Task SaveOptions(CancellationToken cancellationToken) { diff --git a/ASFFreeGames/FreeGames/Strategies/RedlibListFreeGamesStrategy.cs b/ASFFreeGames/FreeGames/Strategies/RedlibListFreeGamesStrategy.cs index a43df1b..9538c5c 100644 --- a/ASFFreeGames/FreeGames/Strategies/RedlibListFreeGamesStrategy.cs +++ b/ASFFreeGames/FreeGames/Strategies/RedlibListFreeGamesStrategy.cs @@ -155,7 +155,14 @@ private async Task> DoDownloadUsingInstance long dateMillis = date.ToUnixTimeMilliseconds(); - return entries.Select(entry => entry.ToRedditGameEntry(dateMillis)).ToArray(); + List redditGameEntries = []; + + // ReSharper disable once LoopCanBeConvertedToQuery + foreach (RedlibGameEntry entry in entries) { + redditGameEntries.Add(entry.ToRedditGameEntry(dateMillis)); + } + + return redditGameEntries; } private async Task> DownloadUsingInstance(SimpleHttpClient client, Uri uri, uint retry, CancellationToken cancellationToken) {