diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index 816576760..4e984420f 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -313,9 +313,14 @@ namespace ArchiSteamFarm { return null; } - internal static string GetAPIStatus() { + internal static string GetAPIStatus(IDictionary bots) { + if (bots == null) { + ASF.ArchiLogger.LogNullError(nameof(bots)); + return null; + } + var response = new { - Bots + Bots = bots }; try { @@ -621,6 +626,8 @@ namespace ArchiSteamFarm { return await Response2FAConfirm(steamID, args[1], false).ConfigureAwait(false); case "!2FAOK": return await Response2FAConfirm(steamID, args[1], true).ConfigureAwait(false); + case "!API": + return ResponseAPI(steamID, args[1]); case "!ADDLICENSE": if (args.Length > 2) { return await ResponseAddLicense(steamID, args[1], args[2]).ConfigureAwait(false); @@ -1988,13 +1995,27 @@ namespace ArchiSteamFarm { private static string ResponseAPI(ulong steamID) { if (steamID != 0) { - return IsOwner(steamID) ? FormatStaticResponse(GetAPIStatus()) : null; + return IsOwner(steamID) ? FormatStaticResponse(GetAPIStatus(Bots)) : null; } ASF.ArchiLogger.LogNullError(nameof(steamID)); return null; } + private static string ResponseAPI(ulong steamID, string botNames) { + if ((steamID == 0) || string.IsNullOrEmpty(botNames)) { + ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botNames)); + return null; + } + + HashSet bots = GetBots(botNames); + if ((bots == null) || (bots.Count == 0)) { + return IsOwner(steamID) ? FormatStaticResponse(string.Format(Strings.BotNotFound, botNames)) : null; + } + + return GetAPIStatus(Bots.Where(kv => bots.Contains(kv.Value)).ToDictionary(kv => kv.Key, kv => kv.Value)); + } + private static string ResponseExit(ulong steamID) { if (steamID == 0) { ASF.ArchiLogger.LogNullError(nameof(steamID)); diff --git a/ArchiSteamFarm/WCF.cs b/ArchiSteamFarm/WCF.cs index c043df15f..68bde4deb 100644 --- a/ArchiSteamFarm/WCF.cs +++ b/ArchiSteamFarm/WCF.cs @@ -50,7 +50,7 @@ namespace ArchiSteamFarm { StopServer(); } - public string GetStatus() => Program.GlobalConfig.SteamOwnerID == 0 ? "{}" : Bot.GetAPIStatus(); + public string GetStatus() => Program.GlobalConfig.SteamOwnerID == 0 ? "{}" : Bot.GetAPIStatus(Bot.Bots); public string HandleCommand(string input) { if (string.IsNullOrEmpty(input)) {