Add unused keys response

This commit is contained in:
JustArchi
2017-01-05 01:49:58 +01:00
parent a005886647
commit 3a0afba858

View File

@@ -2083,7 +2083,9 @@ namespace ArchiSteamFarm {
bool distribute = !redeemFlags.HasFlag(ERedeemFlags.SkipDistribution) && (redeemFlags.HasFlag(ERedeemFlags.ForceDistribution) || BotConfig.RedeemingPreferences.HasFlag(BotConfig.ERedeemingPreferences.Distributing));
message = message.Replace(",", Environment.NewLine);
HashSet<string> unusedKeys = new HashSet<string>();
StringBuilder response = new StringBuilder();
using (StringReader reader = new StringReader(message)) {
using (IEnumerator<Bot> enumerator = Bots.OrderBy(bot => bot.Key).Select(bot => bot.Value).GetEnumerator()) {
string key = reader.ReadLine();
@@ -2094,6 +2096,8 @@ namespace ArchiSteamFarm {
continue; // Keep current bot
}
unusedKeys.Add(key);
if ((redeemFlags.HasFlag(ERedeemFlags.SkipInitial) && (currentBot == this)) || !currentBot.IsConnectedAndLoggedOn) {
currentBot = null; // Either bot will be changed, or loop aborted
} else {
@@ -2117,6 +2121,10 @@ namespace ArchiSteamFarm {
response.Append(Environment.NewLine + "<" + currentBot.BotName + "> Key: " + key + " | Status: " + result.PurchaseResult + ((result.Items != null) && (result.Items.Count > 0) ? " | Items: " + string.Join("", result.Items) : ""));
if (result.PurchaseResult == ArchiHandler.PurchaseResponseCallback.EPurchaseResult.OK) {
unusedKeys.Remove(key);
}
key = reader.ReadLine(); // Next key
if (result.PurchaseResult == ArchiHandler.PurchaseResponseCallback.EPurchaseResult.OK) {
@@ -2155,6 +2163,11 @@ namespace ArchiSteamFarm {
case ArchiHandler.PurchaseResponseCallback.EPurchaseResult.InvalidKey:
case ArchiHandler.PurchaseResponseCallback.EPurchaseResult.OK:
alreadyHandled = true; // This key is already handled, as we either redeemed it or we're sure it's dupe/invalid
if (otherResult.PurchaseResult == ArchiHandler.PurchaseResponseCallback.EPurchaseResult.OK) {
unusedKeys.Remove(key);
}
break;
}
@@ -2190,7 +2203,11 @@ namespace ArchiSteamFarm {
}
}
return response.Length == 0 ? null : response.ToString();
if (unusedKeys.Count > 0) {
response.Append(Environment.NewLine + "Unused keys: " + string.Join(", ", unusedKeys));
}
return response.Length > 0 ? response.ToString() : null;
}
private static async Task<string> ResponseRedeem(ulong steamID, string botName, string message, ERedeemFlags redeemFlags = ERedeemFlags.None) {