From 641cf5a350ff7998f3b80ae34ba318d7ac88e11c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Domeradzki?= Date: Mon, 30 Sep 2024 22:45:02 +0200 Subject: [PATCH] Rewrite points balance from AWH to AH --- .../Steam/Integration/ArchiHandler.cs | 41 +++++++++++++++++++ .../Steam/Integration/ArchiWebHandler.cs | 1 + ArchiSteamFarm/Steam/Interaction/Commands.cs | 2 +- 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/ArchiSteamFarm/Steam/Integration/ArchiHandler.cs b/ArchiSteamFarm/Steam/Integration/ArchiHandler.cs index 23e0c5ca55300..f4787fba8cb04 100644 --- a/ArchiSteamFarm/Steam/Integration/ArchiHandler.cs +++ b/ArchiSteamFarm/Steam/Integration/ArchiHandler.cs @@ -359,6 +359,47 @@ public async IAsyncEnumerable GetMyInventoryAsync(uint appID = Asset.Stea return body.games.ToDictionary(static game => (uint) game.appid, static game => game.name); } + [PublicAPI] + public async Task GetPointsBalance() { + if (Client == null) { + throw new InvalidOperationException(nameof(Client)); + } + + if (!Client.IsConnected) { + return null; + } + + if (Client.SteamID == null) { + throw new InvalidOperationException(nameof(Client.SteamID)); + } + + ulong steamID = Client.SteamID; + + if (steamID == 0) { + throw new InvalidOperationException(nameof(Client.SteamID)); + } + + CLoyaltyRewards_GetSummary_Request request = new() { steamid = steamID }; + + SteamUnifiedMessages.ServiceMethodResponse response; + + try { + response = await UnifiedLoyaltyRewards.SendMessage(x => x.GetSummary(request)).ToLongRunningTask().ConfigureAwait(false); + } catch (Exception e) { + ArchiLogger.LogGenericWarningException(e); + + return null; + } + + if (response.Result != EResult.OK) { + return null; + } + + CLoyaltyRewards_GetSummary_Response body = response.GetDeserializedResponse(); + + return body.summary?.points; + } + [PublicAPI] public async Task GetSteamGuardStatus() { if (Client == null) { diff --git a/ArchiSteamFarm/Steam/Integration/ArchiWebHandler.cs b/ArchiSteamFarm/Steam/Integration/ArchiWebHandler.cs index 6e4c5b692c7a0..cc7616a88298b 100644 --- a/ArchiSteamFarm/Steam/Integration/ArchiWebHandler.cs +++ b/ArchiSteamFarm/Steam/Integration/ArchiWebHandler.cs @@ -394,6 +394,7 @@ public async IAsyncEnumerable GetInventoryAsync(ulong steamID = 0, uint a } } + [Obsolete($"Use {nameof(ArchiHandler)}.{nameof(ArchiHandler.GetPointsBalance)} instead, this endpoint will be removed in the future version")] [PublicAPI] public async Task GetPointsBalance() { string? accessToken = Bot.AccessToken; diff --git a/ArchiSteamFarm/Steam/Interaction/Commands.cs b/ArchiSteamFarm/Steam/Interaction/Commands.cs index b8f0185b5acc4..4c83194b9c143 100644 --- a/ArchiSteamFarm/Steam/Interaction/Commands.cs +++ b/ArchiSteamFarm/Steam/Interaction/Commands.cs @@ -2309,7 +2309,7 @@ internal void OnNewLicenseList() { return FormatBotResponse(Strings.BotNotConnected); } - uint? points = await Bot.ArchiWebHandler.GetPointsBalance().ConfigureAwait(false); + long? points = await Bot.ArchiHandler.GetPointsBalance().ConfigureAwait(false); return FormatBotResponse(points.HasValue ? Strings.FormatBotPointsBalance(points) : Strings.WarningFailed); }