From 36fa2b8b4dd0828c27efe8c7b86a310170c09f07 Mon Sep 17 00:00:00 2001 From: JustArchi Date: Tue, 26 Feb 2019 19:59:04 +0100 Subject: [PATCH] Add BGR command + API info @mrburrburr you might want to somehow make use of it (maybe show next to key icon? I don't know) --- ArchiSteamFarm/Bot.cs | 3 ++ ArchiSteamFarm/BotDatabase.cs | 6 ++- ArchiSteamFarm/Commands.cs | 43 +++++++++++++++++++ .../Localization/Strings.Designer.cs | 9 ++++ ArchiSteamFarm/Localization/Strings.resx | 4 ++ 5 files changed, 63 insertions(+), 2 deletions(-) diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index 46710dc08..6586ada63 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -78,6 +78,9 @@ namespace ArchiSteamFarm { [PublicAPI] public readonly Commands Commands; + [JsonProperty] + public uint GamesToRedeemInBackgroundCount => BotDatabase?.GamesToRedeemInBackgroundCount ?? 0; + [JsonProperty] public bool IsConnectedAndLoggedOn => SteamClient?.SteamID != null; diff --git a/ArchiSteamFarm/BotDatabase.cs b/ArchiSteamFarm/BotDatabase.cs index c8a9772a7..008d14917 100644 --- a/ArchiSteamFarm/BotDatabase.cs +++ b/ArchiSteamFarm/BotDatabase.cs @@ -32,14 +32,16 @@ using Newtonsoft.Json; namespace ArchiSteamFarm { internal sealed class BotDatabase : IDisposable { - internal bool HasGamesToRedeemInBackground { + internal uint GamesToRedeemInBackgroundCount { get { lock (GamesToRedeemInBackground) { - return GamesToRedeemInBackground.Count > 0; + return (uint) GamesToRedeemInBackground.Count; } } } + internal bool HasGamesToRedeemInBackground => GamesToRedeemInBackgroundCount > 0; + [JsonProperty(Required = Required.DisallowNull)] private readonly ConcurrentHashSet BlacklistedFromTradesSteamIDs = new ConcurrentHashSet(); diff --git a/ArchiSteamFarm/Commands.cs b/ArchiSteamFarm/Commands.cs index e70daf374..495ca8095 100644 --- a/ArchiSteamFarm/Commands.cs +++ b/ArchiSteamFarm/Commands.cs @@ -129,6 +129,9 @@ namespace ArchiSteamFarm { case "BALANCE": return ResponseWalletBalance(steamID); + case "BGR": + + return ResponseBackgroundGamesRedeemer(steamID); case "BL": return ResponseBlacklist(steamID); @@ -218,6 +221,9 @@ namespace ArchiSteamFarm { case "BALANCE": return await ResponseWalletBalance(steamID, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false); + case "BGR": + + return await ResponseBackgroundGamesRedeemer(steamID, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false); case "BL": return await ResponseBlacklist(steamID, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false); @@ -890,6 +896,43 @@ namespace ArchiSteamFarm { return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } + private string ResponseBackgroundGamesRedeemer(ulong steamID) { + if (steamID == 0) { + Bot.ArchiLogger.LogNullError(nameof(steamID)); + + return null; + } + + if (!Bot.HasPermission(steamID, BotConfig.EPermission.Master)) { + return null; + } + + uint count = Bot.GamesToRedeemInBackgroundCount; + + return FormatBotResponse(string.Format(Strings.BotGamesToRedeemInBackgroundCount, count)); + } + + [ItemCanBeNull] + private static async Task ResponseBackgroundGamesRedeemer(ulong steamID, string botNames) { + if ((steamID == 0) || string.IsNullOrEmpty(botNames)) { + ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botNames)); + + return null; + } + + HashSet bots = Bot.GetBots(botNames); + + if ((bots == null) || (bots.Count == 0)) { + return ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(Strings.BotNotFound, botNames)) : null; + } + + IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseBackgroundGamesRedeemer(steamID)))).ConfigureAwait(false); + + List responses = new List(results.Where(result => !string.IsNullOrEmpty(result))); + + return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; + } + private string ResponseBlacklist(ulong steamID) { if (steamID == 0) { Bot.ArchiLogger.LogNullError(nameof(steamID)); diff --git a/ArchiSteamFarm/Localization/Strings.Designer.cs b/ArchiSteamFarm/Localization/Strings.Designer.cs index 137dcad46..c5b65d113 100644 --- a/ArchiSteamFarm/Localization/Strings.Designer.cs +++ b/ArchiSteamFarm/Localization/Strings.Designer.cs @@ -312,6 +312,15 @@ namespace ArchiSteamFarm.Localization { } } + /// + /// Wyszukuje zlokalizowany ciąg podobny do ciągu Bot has {0} games remaining in its background queue.. + /// + public static string BotGamesToRedeemInBackgroundCount { + get { + return ResourceManager.GetString("BotGamesToRedeemInBackgroundCount", resourceCulture); + } + } + /// /// Wyszukuje zlokalizowany ciąg podobny do ciągu Bot has no wallet.. /// diff --git a/ArchiSteamFarm/Localization/Strings.resx b/ArchiSteamFarm/Localization/Strings.resx index a9efdc63e..8f9864968 100644 --- a/ArchiSteamFarm/Localization/Strings.resx +++ b/ArchiSteamFarm/Localization/Strings.resx @@ -713,4 +713,8 @@ StackTrace: Response: {0} {0} will be replaced by the generated response (string) + + Bot has {0} games remaining in its background queue. + {0} will be replaced by remaining number of games in BGR's queue + \ No newline at end of file