From 1a2616c64804b92d82fa8cef04ad08f11f9b39fb Mon Sep 17 00:00:00 2001 From: JustArchi Date: Sat, 13 Feb 2016 23:21:47 +0100 Subject: [PATCH] Make !play accept more than one game, #106 --- ArchiSteamFarm/Bot.cs | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index fa4d80004b53a..7d381838af18e 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -777,14 +777,24 @@ internal static async Task ResponseAddLicense(string botName, string gam return await bot.ResponseAddLicense(gameID).ConfigureAwait(false); } - internal async Task ResponsePlay(uint gameID) { - await CardsFarmer.SwitchToManualMode(gameID != 0).ConfigureAwait(false); - ArchiHandler.PlayGames(gameID); + internal async Task ResponsePlay(HashSet gameIDs) { + if (gameIDs == null || gameIDs.Count == 0) { + return null; + } + + if (gameIDs.Contains(0)) { + await CardsFarmer.SwitchToManualMode(false).ConfigureAwait(false); + ArchiHandler.PlayGames(0); + } else { + await CardsFarmer.SwitchToManualMode(true).ConfigureAwait(false); + ArchiHandler.PlayGames(gameIDs); + } + return "Done!"; } - internal static async Task ResponsePlay(string botName, string game) { - if (string.IsNullOrEmpty(botName) || string.IsNullOrEmpty(game)) { + internal static async Task ResponsePlay(string botName, string games) { + if (string.IsNullOrEmpty(botName) || string.IsNullOrEmpty(games)) { return null; } @@ -793,12 +803,22 @@ internal static async Task ResponsePlay(string botName, string game) { return "Couldn't find any bot named " + botName + "!"; } - uint gameID; - if (!uint.TryParse(game, out gameID)) { - return "Couldn't parse game as a number!"; + string[] gameIDs = games.Split(','); + + HashSet gamesToPlay = new HashSet(); + foreach (string game in gameIDs) { + uint gameID; + if (!uint.TryParse(game, out gameID)) { + continue; + } + gamesToPlay.Add(gameID); + } + + if (gamesToPlay.Count == 0) { + return "Couldn't parse any games given!"; } - return await bot.ResponsePlay(gameID).ConfigureAwait(false); + return await bot.ResponsePlay(gamesToPlay).ConfigureAwait(false); } internal async Task ResponseStart() {