diff --git a/ASFFreeGames/ASFFreeGamesPlugin.cs b/ASFFreeGames/ASFFreeGamesPlugin.cs index cd96e28..d23f445 100644 --- a/ASFFreeGames/ASFFreeGamesPlugin.cs +++ b/ASFFreeGames/ASFFreeGamesPlugin.cs @@ -127,6 +127,12 @@ public async void CollectGamesOnClock(object? source) { Array.Sort(reorderedBots, comparison); } + if (reorderedBots.Length == 0) { + ArchiLogger.LogGenericDebug("no viable bot found for freegame scheduled operation"); + + return; + } + if (!cts.IsCancellationRequested) { string cmd = $"FREEGAMES {FreeGamesCommand.CollectInternalCommandString} " + string.Join(' ', reorderedBots.Select(static bot => bot.BotName)); await OnBotCommand(null!, EAccess.None, cmd, cmd.Split()).ConfigureAwait(false); diff --git a/ASFFreeGames/Commands/FreeGamesCommand.cs b/ASFFreeGames/Commands/FreeGamesCommand.cs index 6d6b5f1..113f8ad 100644 --- a/ASFFreeGames/Commands/FreeGamesCommand.cs +++ b/ASFFreeGames/Commands/FreeGamesCommand.cs @@ -122,7 +122,7 @@ internal sealed class FreeGamesCommand : IBotCommand, IDisposable { } private async Task HandleCollectCommand(Bot? bot) { - int collected = await CollectGames(bot is not null ? new[] { bot } : Context.Bots, ECollectGameRequestSource.RequestedByUser, Context.CancellationToken).ConfigureAwait(false); + int collected = await CollectGames(bot is not null ? [bot] : Context.Bots.ToArray(), ECollectGameRequestSource.RequestedByUser, Context.CancellationToken).ConfigureAwait(false); return FormatBotResponse(bot, $"Collected a total of {collected} free game(s)"); } @@ -134,10 +134,21 @@ internal sealed class FreeGamesCommand : IBotCommand, IDisposable { } private async ValueTask HandleInternalCollectCommand(Bot? bot, string[] args, CancellationToken cancellationToken) { - Dictionary botMap = Context.Bots.ToDictionary(static b => b.BotName, static b => b, StringComparer.InvariantCultureIgnoreCase); - int collected = await CollectGames(args.Skip(2).Select(botName => botMap[botName]), ECollectGameRequestSource.Scheduled, cancellationToken).ConfigureAwait(false); + Dictionary botMap = Context.Bots.ToDictionary(static b => b.BotName.Trim(), static b => b, StringComparer.InvariantCultureIgnoreCase); - return FormatBotResponse(bot, $"Collected a total of {collected} free game(s)"); + Bot[] bots = args.Skip(2).Select(botName => botMap.GetValueOrDefault(botName.Trim())).Where(static b => b is not null).ToArray()!; + + if (bots.Length == 0) { + if (bot is null) { + return null; + } + + bots = [bot]; + } + + 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}")); } private async Task SaveOptions(CancellationToken cancellationToken) { diff --git a/Directory.Build.props b/Directory.Build.props index 6bf6713..b6fa018 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -3,7 +3,7 @@ ASFFreeGames - 1.5.1.0 + 1.5.2.0 net8.0