Skip to content

Commit

Permalink
fixing #110 by removing ToArray() calls
Browse files Browse the repository at this point in the history
  • Loading branch information
maxisoft committed Dec 3, 2024
1 parent 9b5edd8 commit 8c04039
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
15 changes: 12 additions & 3 deletions ASFFreeGames/Commands/FreeGamesCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,18 @@ public void Dispose() {
private async ValueTask<string?> HandleInternalCollectCommand(Bot? bot, string[] args, CancellationToken cancellationToken) {
Dictionary<string, Bot> 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<Bot> 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;
}
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,14 @@ private async Task<IReadOnlyCollection<RedditGameEntry>> DoDownloadUsingInstance

long dateMillis = date.ToUnixTimeMilliseconds();

return entries.Select(entry => entry.ToRedditGameEntry(dateMillis)).ToArray();
List<RedditGameEntry> redditGameEntries = [];

// ReSharper disable once LoopCanBeConvertedToQuery
foreach (RedlibGameEntry entry in entries) {
redditGameEntries.Add(entry.ToRedditGameEntry(dateMillis));
}

return redditGameEntries;
}

private async Task<IReadOnlyCollection<RedditGameEntry>> DownloadUsingInstance(SimpleHttpClient client, Uri uri, uint retry, CancellationToken cancellationToken) {
Expand Down

0 comments on commit 8c04039

Please sign in to comment.