added a menu to decide what to do with trade confirmations

This commit is contained in:
Carson McManus 2016-08-26 09:34:28 -04:00
parent bc46eeba18
commit 3055a27288

View file

@ -60,6 +60,10 @@ public static class Program
{ {
action = "setup"; action = "setup";
} }
else if (args[i] == "trade")
{
action = "trade";
}
else if (args[i] == "encrypt") else if (args[i] == "encrypt")
{ {
action = "encrypt"; action = "encrypt";
@ -124,7 +128,7 @@ public static class Program
throw new NotSupportedException(); throw new NotSupportedException();
break; break;
case "trade": case "trade":
TradeList(user); Trade(user);
break; break;
case "accept-all": case "accept-all":
AcceptAllTrades(user); AcceptAllTrades(user);
@ -303,14 +307,14 @@ public static class Program
return true; return true;
} }
static void TradeList(string user = "") static void Trade(string user = "")
{ {
if (Verbose) Console.WriteLine("Opening manifest..."); if (Verbose) Console.WriteLine("Opening manifest...");
Manifest = Manifest.GetManifest(true); Manifest = Manifest.GetManifest(true);
if (Verbose) Console.WriteLine("Reading accounts from manifest..."); if (Verbose) Console.WriteLine("Reading accounts from manifest...");
if (Manifest.Encrypted) if (Manifest.Encrypted)
{ {
string passkey = Manifest.PromptForPassKey(); var passkey = Manifest.PromptForPassKey();
SteamGuardAccounts = Manifest.GetAllAccounts(passkey); SteamGuardAccounts = Manifest.GetAllAccounts(passkey);
} }
else else
@ -323,35 +327,117 @@ public static class Program
return; return;
} }
for (int i = 0; i < SteamGuardAccounts.Length; i++) foreach (var account in SteamGuardAccounts)
{ {
SteamGuardAccount account = SteamGuardAccounts[i];
if (user != "") if (user != "")
{ if (!string.Equals(account.AccountName, user, StringComparison.CurrentCultureIgnoreCase))
if (account.AccountName.ToLower() == user.ToLower())
{
showTradeConfirmations(account);
break; break;
processConfirmations(account);
} }
} }
enum TradeAction
{
Accept = 1,
Deny = 0,
Ignore = -1
}
static void processConfirmations(SteamGuardAccount account)
{
if (Verbose) Console.WriteLine("Refeshing Session...");
account.RefreshSession();
Console.WriteLine("Retrieving trade confirmations...");
var trades = account.FetchConfirmations();
var tradeActions = new TradeAction[trades.Length];
for (var i = 0; i < tradeActions.Length; i++)
{
tradeActions[i] = TradeAction.Ignore;
}
if (trades.Length == 0)
{
Console.WriteLine($"No trade confirmations for {account.AccountName}.");
return;
}
var selected = 0;
var colorAccept = ConsoleColor.Green;
var colorDeny = ConsoleColor.Red;
var colorIgnore = ConsoleColor.Gray;
var colorBackground = Console.BackgroundColor;
var confirm = false;
do
{
Console.Clear();
if (selected >= trades.Length)
selected = trades.Length - 1;
else if (selected < 0)
selected = 0;
Console.ResetColor();
Console.WriteLine($"Trade confirmations for {account.AccountName}...");
Console.WriteLine("No action will be made without your confirmation.");
Console.WriteLine("[a]ccept [d]eny [i]gnore [enter] Confirm"); // accept = 1, deny = 0, ignore = -1
Console.WriteLine();
for (var t = 0; t < trades.Length; t++)
{
ConsoleColor itemColor;
switch (tradeActions[t])
{
case TradeAction.Accept:
itemColor = colorAccept;
break;
case TradeAction.Deny:
itemColor = colorDeny;
break;
case TradeAction.Ignore:
itemColor = colorIgnore;
break;
default:
throw new ArgumentOutOfRangeException();
}
if (t == selected)
{
Console.BackgroundColor = itemColor;
Console.ForegroundColor = colorBackground;
}
else else
{ {
showTradeConfirmations(account); Console.ForegroundColor = itemColor;
} Console.BackgroundColor = colorBackground;
}
} }
static void showTradeConfirmations(SteamGuardAccount account) Console.WriteLine($" [{t}] [{tradeActions[t]}] {trades[t].Description}");
{
Console.WriteLine($"Checking trade confirmations for {account.AccountName}...");
if (Verbose) Console.WriteLine("Refeshing Session...");
account.RefreshSession();
Confirmation[] trades = account.FetchConfirmations();
foreach (var trade in trades)
{
Console.WriteLine($"ID: {trade.ID} Key: {trade.Key} Description: {trade.Description}");
} }
var key = Console.ReadKey();
switch (key.Key)
{
case ConsoleKey.UpArrow:
case ConsoleKey.W:
selected--;
break;
case ConsoleKey.DownArrow:
case ConsoleKey.S:
selected++;
break;
case ConsoleKey.A:
tradeActions[selected] = TradeAction.Accept;
break;
case ConsoleKey.D:
tradeActions[selected] = TradeAction.Deny;
break;
case ConsoleKey.I:
tradeActions[selected] = TradeAction.Ignore;
break;
default:
break;
}
} while (!confirm);
} }
static void AcceptAllTrades(string user = "") static void AcceptAllTrades(string user = "")