2023-02-09 23:37:26 +00:00
|
|
|
// _ _ _ ____ _ _____
|
|
|
|
// / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
|
|
|
|
// / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
|
|
|
|
// / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
|
|
|
|
// /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
|
|
|
|
// |
|
2024-01-08 10:33:28 +00:00
|
|
|
// Copyright 2015-2024 Łukasz "JustArchi" Domeradzki
|
2023-02-09 23:37:26 +00:00
|
|
|
// Contact: JustArchi@JustArchi.net
|
|
|
|
// |
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
// |
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
// |
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.ComponentModel;
|
|
|
|
using System.Globalization;
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using ArchiSteamFarm.Core;
|
|
|
|
using ArchiSteamFarm.Localization;
|
|
|
|
using ArchiSteamFarm.Steam;
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
using SteamKit2;
|
|
|
|
using SteamKit2.Internal;
|
|
|
|
|
|
|
|
namespace ArchiSteamFarm.OfficialPlugins.MobileAuthenticator;
|
|
|
|
|
|
|
|
internal static class Commands {
|
|
|
|
private const byte MaxFinalizationAttempts = 900 / Steam.Security.MobileAuthenticator.CodeInterval;
|
|
|
|
|
|
|
|
internal static async Task<string?> OnBotCommand(Bot bot, EAccess access, string message, string[] args, ulong steamID = 0) {
|
|
|
|
ArgumentNullException.ThrowIfNull(bot);
|
|
|
|
|
|
|
|
if (!Enum.IsDefined(access)) {
|
|
|
|
throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess));
|
|
|
|
}
|
|
|
|
|
2023-11-14 18:12:33 +00:00
|
|
|
ArgumentException.ThrowIfNullOrEmpty(message);
|
2023-02-09 23:37:26 +00:00
|
|
|
|
|
|
|
if ((args == null) || (args.Length == 0)) {
|
|
|
|
throw new ArgumentNullException(nameof(args));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((steamID != 0) && !new SteamID(steamID).IsIndividualAccount) {
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(steamID));
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (args.Length) {
|
|
|
|
case 1:
|
|
|
|
switch (args[0].ToUpperInvariant()) {
|
2023-04-20 19:55:19 +00:00
|
|
|
case "2FAFINALIZEDFORCE":
|
2023-04-20 19:31:30 +00:00
|
|
|
return await ResponseTwoFactorFinalized(access, bot).ConfigureAwait(false);
|
2023-02-09 23:37:26 +00:00
|
|
|
case "2FAINIT":
|
|
|
|
return await ResponseTwoFactorInit(access, bot).ConfigureAwait(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
switch (args[0].ToUpperInvariant()) {
|
2023-02-09 23:39:28 +00:00
|
|
|
case "2FAFINALIZE" when args.Length > 2:
|
2023-02-09 23:37:26 +00:00
|
|
|
return await ResponseTwoFactorFinalize(access, args[1], Utilities.GetArgsAsText(message, 2), steamID).ConfigureAwait(false);
|
2023-02-09 23:39:28 +00:00
|
|
|
case "2FAFINALIZE":
|
2023-02-09 23:37:26 +00:00
|
|
|
return await ResponseTwoFactorFinalize(access, bot, args[1]).ConfigureAwait(false);
|
2023-04-20 19:55:19 +00:00
|
|
|
case "2FAFINALIZED" when args.Length > 2:
|
|
|
|
return await ResponseTwoFactorFinalized(access, args[1], Utilities.GetArgsAsText(message, 2), steamID).ConfigureAwait(false);
|
2023-04-20 19:31:30 +00:00
|
|
|
case "2FAFINALIZED":
|
2023-04-20 19:55:19 +00:00
|
|
|
return await ResponseTwoFactorFinalized(access, bot, args[1]).ConfigureAwait(false);
|
|
|
|
case "2FAFINALIZEDFORCE":
|
|
|
|
return await ResponseTwoFactorFinalized(access, Utilities.GetArgsAsText(args, 1, ","), steamID: steamID).ConfigureAwait(false);
|
2023-02-09 23:39:28 +00:00
|
|
|
case "2FAINIT":
|
|
|
|
return await ResponseTwoFactorInit(access, Utilities.GetArgsAsText(args, 1, ","), steamID).ConfigureAwait(false);
|
2023-02-09 23:37:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2023-02-09 23:39:28 +00:00
|
|
|
private static async Task<string?> ResponseTwoFactorFinalize(EAccess access, Bot bot, string activationCode) {
|
2023-02-09 23:37:26 +00:00
|
|
|
if (!Enum.IsDefined(access)) {
|
|
|
|
throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess));
|
|
|
|
}
|
|
|
|
|
|
|
|
ArgumentNullException.ThrowIfNull(bot);
|
2023-11-14 18:12:33 +00:00
|
|
|
ArgumentException.ThrowIfNullOrEmpty(activationCode);
|
2023-02-09 23:37:26 +00:00
|
|
|
|
|
|
|
if (access < EAccess.Master) {
|
|
|
|
return access > EAccess.None ? bot.Commands.FormatBotResponse(Strings.ErrorAccessDenied) : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bot.HasMobileAuthenticator) {
|
|
|
|
return bot.Commands.FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, nameof(bot.HasMobileAuthenticator)));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!bot.IsConnectedAndLoggedOn) {
|
|
|
|
return bot.Commands.FormatBotResponse(Strings.BotNotConnected);
|
|
|
|
}
|
|
|
|
|
|
|
|
string maFilePath = bot.GetFilePath(Bot.EFileType.MobileAuthenticator);
|
|
|
|
string maFilePendingPath = $"{maFilePath}.PENDING";
|
|
|
|
|
|
|
|
if (!File.Exists(maFilePendingPath)) {
|
|
|
|
return bot.Commands.FormatBotResponse(Strings.NothingFound);
|
|
|
|
}
|
|
|
|
|
|
|
|
string json;
|
|
|
|
|
|
|
|
try {
|
|
|
|
json = await File.ReadAllTextAsync(maFilePendingPath).ConfigureAwait(false);
|
|
|
|
} catch (Exception e) {
|
|
|
|
bot.ArchiLogger.LogGenericException(e);
|
|
|
|
|
|
|
|
return bot.Commands.FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, e.Message));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(json)) {
|
|
|
|
return bot.Commands.FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(json)));
|
|
|
|
}
|
|
|
|
|
|
|
|
Steam.Security.MobileAuthenticator? mobileAuthenticator = JsonConvert.DeserializeObject<Steam.Security.MobileAuthenticator>(json);
|
|
|
|
|
|
|
|
if (mobileAuthenticator == null) {
|
|
|
|
return bot.Commands.FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(json)));
|
|
|
|
}
|
|
|
|
|
|
|
|
mobileAuthenticator.Init(bot);
|
|
|
|
|
|
|
|
MobileAuthenticatorHandler? mobileAuthenticatorHandler = bot.GetHandler<MobileAuthenticatorHandler>();
|
|
|
|
|
|
|
|
if (mobileAuthenticatorHandler == null) {
|
|
|
|
throw new InvalidOperationException(nameof(mobileAuthenticatorHandler));
|
|
|
|
}
|
|
|
|
|
|
|
|
ulong steamTime = await mobileAuthenticator.GetSteamTime().ConfigureAwait(false);
|
|
|
|
|
|
|
|
bool successFinalizing = false;
|
|
|
|
|
|
|
|
for (byte i = 0; i < MaxFinalizationAttempts; i++) {
|
|
|
|
if (i > 0) {
|
|
|
|
steamTime += Steam.Security.MobileAuthenticator.CodeInterval;
|
|
|
|
}
|
|
|
|
|
|
|
|
string? code = mobileAuthenticator.GenerateTokenForTime(steamTime);
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(code)) {
|
|
|
|
return bot.Commands.FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, nameof(mobileAuthenticator.GenerateTokenForTime)));
|
|
|
|
}
|
|
|
|
|
2023-11-14 19:01:29 +00:00
|
|
|
CTwoFactor_FinalizeAddAuthenticator_Response? response = await mobileAuthenticatorHandler.FinalizeAuthenticator(bot.SteamID, activationCode, code, steamTime).ConfigureAwait(false);
|
2023-02-09 23:37:26 +00:00
|
|
|
|
|
|
|
if (response == null) {
|
|
|
|
return bot.Commands.FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, nameof(mobileAuthenticatorHandler.FinalizeAuthenticator)));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (response.want_more) {
|
|
|
|
// OK, whatever
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!response.success) {
|
|
|
|
EResult result = (EResult) response.status;
|
|
|
|
|
|
|
|
return bot.Commands.FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, result));
|
|
|
|
}
|
|
|
|
|
|
|
|
successFinalizing = true;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!successFinalizing) {
|
|
|
|
return bot.Commands.FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.ErrorRequestFailedTooManyTimes, MaxFinalizationAttempts));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!bot.TryImportAuthenticator(mobileAuthenticator)) {
|
|
|
|
return bot.Commands.FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, nameof(bot.TryImportAuthenticator)));
|
|
|
|
}
|
|
|
|
|
|
|
|
string maFileFinishedPath = $"{maFilePath}.NEW";
|
|
|
|
|
|
|
|
try {
|
|
|
|
File.Move(maFilePendingPath, maFileFinishedPath, true);
|
|
|
|
} catch (Exception e) {
|
|
|
|
bot.ArchiLogger.LogGenericException(e);
|
|
|
|
|
|
|
|
return bot.Commands.FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, e.Message));
|
|
|
|
}
|
|
|
|
|
|
|
|
return bot.Commands.FormatBotResponse(Strings.Done);
|
|
|
|
}
|
|
|
|
|
2023-02-09 23:39:28 +00:00
|
|
|
private static async Task<string?> ResponseTwoFactorFinalize(EAccess access, string botNames, string activationCode, ulong steamID = 0) {
|
2023-02-09 23:37:26 +00:00
|
|
|
if (!Enum.IsDefined(access)) {
|
|
|
|
throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess));
|
|
|
|
}
|
|
|
|
|
2023-11-14 18:12:33 +00:00
|
|
|
ArgumentException.ThrowIfNullOrEmpty(botNames);
|
|
|
|
ArgumentException.ThrowIfNullOrEmpty(activationCode);
|
2023-02-09 23:37:26 +00:00
|
|
|
|
|
|
|
if ((steamID != 0) && !new SteamID(steamID).IsIndividualAccount) {
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(steamID));
|
|
|
|
}
|
|
|
|
|
|
|
|
HashSet<Bot>? bots = Bot.GetBots(botNames);
|
|
|
|
|
|
|
|
if ((bots == null) || (bots.Count == 0)) {
|
|
|
|
return access >= EAccess.Owner ? Steam.Interaction.Commands.FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null;
|
|
|
|
}
|
|
|
|
|
2023-02-09 23:39:28 +00:00
|
|
|
IList<string?> results = await Utilities.InParallel(bots.Select(bot => ResponseTwoFactorFinalize(Steam.Interaction.Commands.GetProxyAccess(bot, access, steamID), bot, activationCode))).ConfigureAwait(false);
|
2023-02-09 23:37:26 +00:00
|
|
|
|
2023-12-11 22:55:13 +00:00
|
|
|
List<string> responses = [..results.Where(static result => !string.IsNullOrEmpty(result))];
|
2023-02-09 23:37:26 +00:00
|
|
|
|
|
|
|
return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null;
|
|
|
|
}
|
|
|
|
|
2023-04-20 19:55:19 +00:00
|
|
|
private static async Task<string?> ResponseTwoFactorFinalized(EAccess access, Bot bot, string? activationCode = null) {
|
2023-04-20 19:31:30 +00:00
|
|
|
if (!Enum.IsDefined(access)) {
|
|
|
|
throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess));
|
|
|
|
}
|
|
|
|
|
|
|
|
ArgumentNullException.ThrowIfNull(bot);
|
|
|
|
|
|
|
|
if (access < EAccess.Master) {
|
|
|
|
return access > EAccess.None ? bot.Commands.FormatBotResponse(Strings.ErrorAccessDenied) : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bot.HasMobileAuthenticator) {
|
|
|
|
return bot.Commands.FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, nameof(bot.HasMobileAuthenticator)));
|
|
|
|
}
|
|
|
|
|
|
|
|
string maFilePath = bot.GetFilePath(Bot.EFileType.MobileAuthenticator);
|
|
|
|
string maFilePendingPath = $"{maFilePath}.PENDING";
|
|
|
|
|
|
|
|
if (!File.Exists(maFilePendingPath)) {
|
|
|
|
return bot.Commands.FormatBotResponse(Strings.NothingFound);
|
|
|
|
}
|
|
|
|
|
|
|
|
string json;
|
|
|
|
|
|
|
|
try {
|
|
|
|
json = await File.ReadAllTextAsync(maFilePendingPath).ConfigureAwait(false);
|
|
|
|
} catch (Exception e) {
|
|
|
|
bot.ArchiLogger.LogGenericException(e);
|
|
|
|
|
|
|
|
return bot.Commands.FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, e.Message));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(json)) {
|
|
|
|
return bot.Commands.FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(json)));
|
|
|
|
}
|
|
|
|
|
|
|
|
Steam.Security.MobileAuthenticator? mobileAuthenticator = JsonConvert.DeserializeObject<Steam.Security.MobileAuthenticator>(json);
|
|
|
|
|
|
|
|
if (mobileAuthenticator == null) {
|
|
|
|
return bot.Commands.FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(json)));
|
|
|
|
}
|
|
|
|
|
|
|
|
mobileAuthenticator.Init(bot);
|
|
|
|
|
2023-04-20 19:55:19 +00:00
|
|
|
if (!string.IsNullOrEmpty(activationCode)) {
|
|
|
|
string? generatedCode = await mobileAuthenticator.GenerateToken().ConfigureAwait(false);
|
|
|
|
|
|
|
|
if (generatedCode != activationCode) {
|
|
|
|
return bot.Commands.FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, $"{generatedCode} != {activationCode}"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-20 19:31:30 +00:00
|
|
|
if (!bot.TryImportAuthenticator(mobileAuthenticator)) {
|
|
|
|
return bot.Commands.FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, nameof(bot.TryImportAuthenticator)));
|
|
|
|
}
|
|
|
|
|
|
|
|
string maFileFinishedPath = $"{maFilePath}.NEW";
|
|
|
|
|
|
|
|
try {
|
|
|
|
File.Move(maFilePendingPath, maFileFinishedPath, true);
|
|
|
|
} catch (Exception e) {
|
|
|
|
bot.ArchiLogger.LogGenericException(e);
|
|
|
|
|
|
|
|
return bot.Commands.FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, e.Message));
|
|
|
|
}
|
|
|
|
|
|
|
|
return bot.Commands.FormatBotResponse(Strings.Done);
|
|
|
|
}
|
|
|
|
|
2023-04-20 19:55:19 +00:00
|
|
|
private static async Task<string?> ResponseTwoFactorFinalized(EAccess access, string botNames, string? activationCode = null, ulong steamID = 0) {
|
2023-04-20 19:31:30 +00:00
|
|
|
if (!Enum.IsDefined(access)) {
|
|
|
|
throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess));
|
|
|
|
}
|
|
|
|
|
2023-11-14 18:12:33 +00:00
|
|
|
ArgumentException.ThrowIfNullOrEmpty(botNames);
|
2023-04-20 19:31:30 +00:00
|
|
|
|
|
|
|
if ((steamID != 0) && !new SteamID(steamID).IsIndividualAccount) {
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(steamID));
|
|
|
|
}
|
|
|
|
|
|
|
|
HashSet<Bot>? bots = Bot.GetBots(botNames);
|
|
|
|
|
|
|
|
if ((bots == null) || (bots.Count == 0)) {
|
|
|
|
return access >= EAccess.Owner ? Steam.Interaction.Commands.FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null;
|
|
|
|
}
|
|
|
|
|
2023-04-20 19:55:19 +00:00
|
|
|
IList<string?> results = await Utilities.InParallel(bots.Select(bot => ResponseTwoFactorFinalized(Steam.Interaction.Commands.GetProxyAccess(bot, access, steamID), bot, activationCode))).ConfigureAwait(false);
|
2023-04-20 19:31:30 +00:00
|
|
|
|
2023-12-11 22:55:13 +00:00
|
|
|
List<string> responses = [..results.Where(static result => !string.IsNullOrEmpty(result))];
|
2023-04-20 19:31:30 +00:00
|
|
|
|
|
|
|
return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null;
|
|
|
|
}
|
|
|
|
|
2023-02-09 23:37:26 +00:00
|
|
|
private static async Task<string?> ResponseTwoFactorInit(EAccess access, Bot bot) {
|
|
|
|
if (!Enum.IsDefined(access)) {
|
|
|
|
throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess));
|
|
|
|
}
|
|
|
|
|
|
|
|
ArgumentNullException.ThrowIfNull(bot);
|
|
|
|
|
|
|
|
if (access < EAccess.Master) {
|
|
|
|
return access > EAccess.None ? bot.Commands.FormatBotResponse(Strings.ErrorAccessDenied) : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bot.HasMobileAuthenticator) {
|
|
|
|
return bot.Commands.FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, nameof(bot.HasMobileAuthenticator)));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!bot.IsConnectedAndLoggedOn) {
|
|
|
|
return bot.Commands.FormatBotResponse(Strings.BotNotConnected);
|
|
|
|
}
|
|
|
|
|
|
|
|
MobileAuthenticatorHandler? mobileAuthenticatorHandler = bot.GetHandler<MobileAuthenticatorHandler>();
|
|
|
|
|
|
|
|
if (mobileAuthenticatorHandler == null) {
|
|
|
|
throw new InvalidOperationException(nameof(mobileAuthenticatorHandler));
|
|
|
|
}
|
|
|
|
|
|
|
|
string deviceID = $"android:{Guid.NewGuid()}";
|
|
|
|
|
|
|
|
CTwoFactor_AddAuthenticator_Response? response = await mobileAuthenticatorHandler.AddAuthenticator(bot.SteamID, deviceID).ConfigureAwait(false);
|
|
|
|
|
|
|
|
if (response == null) {
|
|
|
|
return bot.Commands.FormatBotResponse(Strings.WarningFailed);
|
|
|
|
}
|
|
|
|
|
|
|
|
EResult result = (EResult) response.status;
|
|
|
|
|
|
|
|
if (result != EResult.OK) {
|
|
|
|
return bot.Commands.FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, result));
|
|
|
|
}
|
|
|
|
|
2023-12-02 16:00:50 +00:00
|
|
|
MaFileData maFileData = new(response, bot.SteamID, deviceID);
|
2023-02-09 23:37:26 +00:00
|
|
|
|
|
|
|
string maFilePendingPath = $"{bot.GetFilePath(Bot.EFileType.MobileAuthenticator)}.PENDING";
|
|
|
|
string json = JsonConvert.SerializeObject(maFileData, Formatting.Indented);
|
|
|
|
|
|
|
|
try {
|
|
|
|
await File.WriteAllTextAsync(maFilePendingPath, json).ConfigureAwait(false);
|
|
|
|
} catch (Exception e) {
|
|
|
|
bot.ArchiLogger.LogGenericException(e);
|
|
|
|
|
|
|
|
return bot.Commands.FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, e.Message));
|
|
|
|
}
|
|
|
|
|
|
|
|
return bot.Commands.FormatBotResponse(Strings.Done);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static async Task<string?> ResponseTwoFactorInit(EAccess access, string botNames, ulong steamID = 0) {
|
|
|
|
if (!Enum.IsDefined(access)) {
|
|
|
|
throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess));
|
|
|
|
}
|
|
|
|
|
2023-11-14 18:12:33 +00:00
|
|
|
ArgumentException.ThrowIfNullOrEmpty(botNames);
|
2023-02-09 23:37:26 +00:00
|
|
|
|
|
|
|
if ((steamID != 0) && !new SteamID(steamID).IsIndividualAccount) {
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(steamID));
|
|
|
|
}
|
|
|
|
|
|
|
|
HashSet<Bot>? bots = Bot.GetBots(botNames);
|
|
|
|
|
|
|
|
if ((bots == null) || (bots.Count == 0)) {
|
|
|
|
return access >= EAccess.Owner ? Steam.Interaction.Commands.FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
IList<string?> results = await Utilities.InParallel(bots.Select(bot => ResponseTwoFactorInit(Steam.Interaction.Commands.GetProxyAccess(bot, access, steamID), bot))).ConfigureAwait(false);
|
|
|
|
|
2023-12-11 22:55:13 +00:00
|
|
|
List<string> responses = [..results.Where(static result => !string.IsNullOrEmpty(result))];
|
2023-02-09 23:37:26 +00:00
|
|
|
|
|
|
|
return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null;
|
|
|
|
}
|
|
|
|
}
|