From b334c939df05bce1c490d9d29570acc97c56e3de Mon Sep 17 00:00:00 2001 From: JustArchi Date: Thu, 10 Mar 2016 00:40:30 +0100 Subject: [PATCH] Add !2faok --- ArchiSteamFarm/Bot.cs | 59 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index 973b79800..cc6218fe2 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -260,10 +260,17 @@ namespace ArchiSteamFarm { return; } - await BotDatabase.SteamGuardAccount.RefreshSessionAsync().ConfigureAwait(false); + if (!await BotDatabase.SteamGuardAccount.RefreshSessionAsync().ConfigureAwait(false)) { + return; + } + + Confirmation[] confirmations = await BotDatabase.SteamGuardAccount.FetchConfirmationsAsync().ConfigureAwait(false); + if (confirmations == null) { + return; + } try { - foreach (Confirmation confirmation in await BotDatabase.SteamGuardAccount.FetchConfirmationsAsync().ConfigureAwait(false)) { + foreach (Confirmation confirmation in confirmations) { if (BotDatabase.SteamGuardAccount.AcceptConfirmation(confirmation)) { Logging.LogGenericInfo("Accepting confirmation: Success!", BotName); } else { @@ -315,6 +322,8 @@ namespace ArchiSteamFarm { return Response2FA(); case "!2faoff": return Response2FAOff(); + case "!2faok": + return await Response2FAOK().ConfigureAwait(false); case "!exit": Program.Exit(); return null; @@ -341,6 +350,8 @@ namespace ArchiSteamFarm { return Response2FA(args[1]); case "!2faoff": return Response2FAOff(args[1]); + case "!2faok": + return await Response2FAOK(args[1]).ConfigureAwait(false); case "!addlicense": if (args.Length > 2) { return await ResponseAddLicense(args[1], args[2]).ConfigureAwait(false); @@ -527,6 +538,50 @@ namespace ArchiSteamFarm { return bot.Response2FAOff(); } + private async Task Response2FAOK() { + if (BotDatabase.SteamGuardAccount == null) { + return "That bot doesn't have ASF 2FA enabled!"; + } + + if (!await BotDatabase.SteamGuardAccount.RefreshSessionAsync().ConfigureAwait(false)) { + return "Could not refresh steam session!"; + } + + Confirmation[] confirmations = await BotDatabase.SteamGuardAccount.FetchConfirmationsAsync().ConfigureAwait(false); + if (confirmations == null) { + return "No confirmations to confirm!"; + } + + try { + foreach (Confirmation confirmation in confirmations) { + if (BotDatabase.SteamGuardAccount.AcceptConfirmation(confirmation)) { + Logging.LogGenericInfo("Accepting confirmation: Success!", BotName); + } else { + Logging.LogGenericWarning("Accepting confirmation: Failed!", BotName); + } + } + } catch (SteamGuardAccount.WGTokenInvalidException) { + Logging.LogGenericWarning("Accepting confirmation: Failed!", BotName); + Logging.LogGenericWarning("Confirmation could not be accepted because of invalid token exception", BotName); + Logging.LogGenericWarning("If issue persists, consider removing and readding ASF 2FA", BotName); + } + + return "Done!"; + } + + private static async Task Response2FAOK(string botName) { + if (string.IsNullOrEmpty(botName)) { + return null; + } + + Bot bot; + if (!Bots.TryGetValue(botName, out bot)) { + return "Couldn't find any bot named " + botName + "!"; + } + + return await bot.Response2FAOK().ConfigureAwait(false); + } + private async Task ResponseRedeem(string message, bool validate) { if (string.IsNullOrEmpty(message)) { return null;