Skip to content

Commit

Permalink
Make !play accept more than one game, #106
Browse files Browse the repository at this point in the history
  • Loading branch information
JustArchi committed Feb 13, 2016
1 parent 9858c0e commit 1a2616c
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions ArchiSteamFarm/Bot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -777,14 +777,24 @@ internal static async Task<string> ResponseAddLicense(string botName, string gam
return await bot.ResponseAddLicense(gameID).ConfigureAwait(false);
}

internal async Task<string> ResponsePlay(uint gameID) {
await CardsFarmer.SwitchToManualMode(gameID != 0).ConfigureAwait(false);
ArchiHandler.PlayGames(gameID);
internal async Task<string> ResponsePlay(HashSet<uint> 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<string> ResponsePlay(string botName, string game) {
if (string.IsNullOrEmpty(botName) || string.IsNullOrEmpty(game)) {
internal static async Task<string> ResponsePlay(string botName, string games) {
if (string.IsNullOrEmpty(botName) || string.IsNullOrEmpty(games)) {
return null;
}

Expand All @@ -793,12 +803,22 @@ internal static async Task<string> 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<uint> gamesToPlay = new HashSet<uint>();
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<string> ResponseStart() {
Expand Down

0 comments on commit 1a2616c

Please sign in to comment.