Skip to content

Commit

Permalink
Enhance !addlicense to multiple games, closes #108
Browse files Browse the repository at this point in the history
  • Loading branch information
JustArchi committed Feb 16, 2016
1 parent c2cd7ca commit 935e11a
Showing 1 changed file with 32 additions and 10 deletions.
42 changes: 32 additions & 10 deletions ArchiSteamFarm/Bot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -750,17 +750,29 @@ internal static async Task<string> ResponseRedeem(string botName, string message
return await bot.ResponseRedeem(message, validate).ConfigureAwait(false);
}

internal async Task<string> ResponseAddLicense(uint gameID) {
if (gameID == 0) {
internal async Task<string> ResponseAddLicense(HashSet<uint> gameIDs) {
if (gameIDs == null || gameIDs.Count == 0) {
return null;
}

var result = await SteamApps.RequestFreeLicense(gameID);
return "Result: " + result.Result + " | Granted apps: " + string.Join(", ", result.GrantedApps) + " " + string.Join(", ", result.GrantedPackages);
StringBuilder result = new StringBuilder();
foreach (uint gameID in gameIDs) {
SteamApps.FreeLicenseCallback callback;
try {
callback = await SteamApps.RequestFreeLicense(gameID);
} catch (Exception e) {
Logging.LogGenericException(e);
continue;
}

result.AppendLine("Result: " + callback.Result + " | Granted apps: " + string.Join(", ", callback.GrantedApps) + " " + string.Join(", ", callback.GrantedPackages));
}

return result.ToString();
}

internal static async Task<string> ResponseAddLicense(string botName, string game) {
if (string.IsNullOrEmpty(botName) || string.IsNullOrEmpty(game)) {
internal static async Task<string> ResponseAddLicense(string botName, string games) {
if (string.IsNullOrEmpty(botName) || string.IsNullOrEmpty(games)) {
return null;
}

Expand All @@ -769,12 +781,22 @@ internal static async Task<string> ResponseAddLicense(string botName, string gam
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> gamesToRedeem = new HashSet<uint>();
foreach (string game in gameIDs) {
uint gameID;
if (!uint.TryParse(game, out gameID)) {
continue;
}
gamesToRedeem.Add(gameID);
}

if (gamesToRedeem.Count == 0) {
return "Couldn't parse any games given!";
}

return await bot.ResponseAddLicense(gameID).ConfigureAwait(false);
return await bot.ResponseAddLicense(gamesToRedeem).ConfigureAwait(false);
}

internal async Task<string> ResponsePlay(HashSet<uint> gameIDs) {
Expand Down

0 comments on commit 935e11a

Please sign in to comment.