From 35075e16b602bf2b2fd2858d00b8c981eb951080 Mon Sep 17 00:00:00 2001 From: Chr_ Date: Sat, 28 May 2022 10:36:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=98=BE=E7=A4=BA=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ASFEnhance/AssemblyInfo.cs | 4 +- ASFEnhance/Cart/Command.cs | 43 +++++++++++++++------- ASFEnhance/Cart/WebRequest.cs | 20 +++++----- ASFEnhance/Data/SteamGameID.cs | 19 ++++++---- ASFEnhance/Event/WebRequest.cs | 1 - ASFEnhance/Localization/Langs.Designer.cs | 8 ++-- ASFEnhance/Localization/Langs.en-US.resx | 8 ++-- ASFEnhance/Localization/Langs.resx | 8 ++-- ASFEnhance/Localization/Langs.zh-Hans.resx | 8 ++-- ASFEnhance/Store/Command.cs | 20 ++++++---- ASFEnhance/Store/Response.cs | 5 +++ ASFEnhance/Utils.cs | 6 +-- 12 files changed, 89 insertions(+), 61 deletions(-) diff --git a/ASFEnhance/AssemblyInfo.cs b/ASFEnhance/AssemblyInfo.cs index 19664ccb..25029acf 100644 --- a/ASFEnhance/AssemblyInfo.cs +++ b/ASFEnhance/AssemblyInfo.cs @@ -1,8 +1,8 @@ using System.Reflection; [assembly: System.CLSCompliant(false)] -[assembly: AssemblyVersion("1.6.2.451")] -[assembly: AssemblyFileVersion("1.6.2.451")] +[assembly: AssemblyVersion("1.6.2.457")] +[assembly: AssemblyFileVersion("1.6.2.457")] [assembly: AssemblyCopyright("Copyright © 2022 Chr_")] [assembly: AssemblyProduct("ASFEnhance")] diff --git a/ASFEnhance/Cart/Command.cs b/ASFEnhance/Cart/Command.cs index b751487d..89df51c8 100644 --- a/ASFEnhance/Cart/Command.cs +++ b/ASFEnhance/Cart/Command.cs @@ -175,31 +175,46 @@ internal static class Command return bot.FormatBotResponse(Strings.BotNotConnected); } - Dictionary gameIDs = FetchGameIDs(query, SteamGameIDType.App); + Dictionary itemIDs = FetchItemIDs(query); + + if (itemIDs.Count < 2) + { + return bot.FormatBotResponse("参数错误, 最少需要两个参数"); + } + else if (itemIDs.First().Value.GameType == SteamGameIDType.Error) + { + return bot.FormatBotResponse(string.Format(Langs.ArgumentNotInteger, "AppID")); + } StringBuilder response = new(); response.AppendLine(Langs.MultipleLineResult); - foreach (KeyValuePair item in gameIDs) + uint appID = itemIDs.First().Value.GameID; + response.AppendLine(string.Format("AppID : {0}", appID)); + + bool first = true; + foreach (KeyValuePair item in itemIDs) { - if (response.Length != 0) { response.AppendLine(); } + if (first) + { + first = false; + continue; + } string input = item.Key; - SteamGameID gameID = item.Value; + SteamGameID itemID = item.Value; - switch (gameID.GameType) + if (itemID.GameType == SteamGameIDType.Item) { - case SteamGameIDType.Sub: - case SteamGameIDType.Bundle: - bool? success = await WebRequest.AddCart(bot, gameID).ConfigureAwait(false); - response.AppendLine(bot.FormatBotResponse(string.Format(Strings.BotAddLicense, input, success == null ? Langs.CartNetworkError : (bool)success ? EResult.OK : EResult.Fail))); - break; - default: - response.AppendLine(bot.FormatBotResponse(string.Format(Langs.CartInvalidType, input))); - break; + EResult? success = await WebRequest.AddCart(bot, appID, itemID.GameID).ConfigureAwait(false); + response.AppendLine(bot.FormatBotResponse(string.Format("- {0}|{1} : {2}", appID, itemID.GameID, success == null ? Langs.CartNetworkError : success))); + } + else + { + response.AppendLine(bot.FormatBotResponse(string.Format("- {0} : {1}", input, string.Format(Langs.ArgumentNotInteger, "itemID")))); } } - return response.Length > 0 ? response.ToString() : null; + return response.ToString(); } /// diff --git a/ASFEnhance/Cart/WebRequest.cs b/ASFEnhance/Cart/WebRequest.cs index 4024d90f..31c104c8 100644 --- a/ASFEnhance/Cart/WebRequest.cs +++ b/ASFEnhance/Cart/WebRequest.cs @@ -2,10 +2,12 @@ using ArchiSteamFarm.Core; using ArchiSteamFarm.Steam; +using ArchiSteamFarm.Steam.Data; using ArchiSteamFarm.Web.Responses; using ASFEnhance.Data; using ASFEnhance.Localization; using static ASFEnhance.Cart.Response; +using static ASFEnhance.Data.SteamGameID; using static ASFEnhance.Utils; namespace ASFEnhance.Cart @@ -59,14 +61,11 @@ internal static class WebRequest Uri request = new(SteamStoreURL, "/cart/"); Uri referer = new(SteamStoreURL, $"/{type}/{subID}"); - Random random = new(); - Dictionary data = new(5, StringComparer.Ordinal) { { "action", "add_to_cart" }, { type + "id", subID.ToString() }, { "originating_snr", "1_direct-navigation__" }, - { "snr", string.Format("{0}_{1}_{2}__{3}", 1, random.Next(1, 10), random.Next(1, 10), random.Next(100, 999)) } }; HtmlDocumentResponse? response = await bot.ArchiWebHandler.UrlPostToHtmlDocumentWithSession(request, data: data, referer: referer).ConfigureAwait(false); @@ -75,19 +74,17 @@ internal static class WebRequest } /// - /// 添加购物车 + /// 添加购物车(游戏物品) /// /// /// /// /// - internal static async Task AddCart(Bot bot, uint appID, uint classID) + internal static async Task AddCart(Bot bot, uint appID, uint classID) { Uri request = new(SteamStoreURL, "/cart/addtocart"); Uri referer = new(SteamStoreURL, $"/itemstore/{appID}/detail/{classID}/"); - Random random = new(); - Dictionary data = new(5, StringComparer.Ordinal) { { "action", "add_to_cart" }, @@ -95,9 +92,14 @@ internal static class WebRequest { "microtxnassetclassid", classID.ToString() }, }; - HtmlDocumentResponse? response = await bot.ArchiWebHandler.UrlPostToHtmlDocumentWithSession(request, data: data, referer: referer).ConfigureAwait(false); + ObjectResponse? response = await bot.ArchiWebHandler.UrlPostToJsonObjectWithSession(request, data: data, referer: referer).ConfigureAwait(false); - return response != null; + if (response == null) + { + return null; + } + + return response.Content.Result; } /// diff --git a/ASFEnhance/Data/SteamGameID.cs b/ASFEnhance/Data/SteamGameID.cs index c3d5d717..7eac8f16 100644 --- a/ASFEnhance/Data/SteamGameID.cs +++ b/ASFEnhance/Data/SteamGameID.cs @@ -1,20 +1,23 @@ -namespace ASFEnhance.Data +using ASFEnhance.Localization; + +namespace ASFEnhance.Data { internal sealed class SteamGameID { - internal SteamGameIDType GameType { get; set; } - internal uint GameID { get; set; } - + public SteamGameIDType GameType { get; set; } + public uint GameID { get; set; } - - internal SteamGameID(SteamGameIDType type, uint gameID) + public SteamGameID(SteamGameIDType type, uint gameID) { GameType = type; GameID = gameID; } - } - + public override string ToString() + { + return $"{GameType}/{GameID}"; + } + } internal enum SteamGameIDType { Error = 0, diff --git a/ASFEnhance/Event/WebRequest.cs b/ASFEnhance/Event/WebRequest.cs index 3d9f3146..7fb7a172 100644 --- a/ASFEnhance/Event/WebRequest.cs +++ b/ASFEnhance/Event/WebRequest.cs @@ -58,7 +58,6 @@ internal static class WebRequest Dictionary data = new(3, StringComparer.Ordinal) { - { "sessionid" , bot.GetBotSessionID() }, { "authwgtoken", authwgToken }, { "door_index", "5" }, }; diff --git a/ASFEnhance/Localization/Langs.Designer.cs b/ASFEnhance/Localization/Langs.Designer.cs index 6aa6a048..080053d6 100644 --- a/ASFEnhance/Localization/Langs.Designer.cs +++ b/ASFEnhance/Localization/Langs.Designer.cs @@ -376,7 +376,7 @@ internal static string CartEmptyResponse { } /// - /// 查找类似 {0}: 类型无效 [SUB|BUNDLE] 的本地化字符串。 + /// 查找类似 - {0}: 类型无效 [SUB|BUNDLE] 的本地化字符串。 /// internal static string CartInvalidType { get { @@ -394,7 +394,7 @@ internal static string CartIsEmpty { } /// - /// 查找类似 {0} {1} {2:F2} 的本地化字符串。 + /// 查找类似 - {0} {1} {2:F2} 的本地化字符串。 /// internal static string CartItemInfo { get { @@ -1366,7 +1366,7 @@ internal static string SomethingIsNull { } /// - /// 查找类似 {0}/{1} {2} {3:F2} {4} 的本地化字符串。 + /// 查找类似 - {0}/{1} {2} {3:F2} {4} 的本地化字符串。 /// internal static string StoreItem { get { @@ -1375,7 +1375,7 @@ internal static string StoreItem { } /// - /// 查找类似 {0}/{1}: {2} 的本地化字符串。 + /// 查找类似 - {0}: {1} 的本地化字符串。 /// internal static string StoreItemHeader { get { diff --git a/ASFEnhance/Localization/Langs.en-US.resx b/ASFEnhance/Localization/Langs.en-US.resx index b10b6f70..06022342 100644 --- a/ASFEnhance/Localization/Langs.en-US.resx +++ b/ASFEnhance/Localization/Langs.en-US.resx @@ -130,13 +130,13 @@ Response is empty - {0}: Invalid type [SUB|BUNDLE] + - {0}: Invalid type [SUB|BUNDLE] Shopping cart is emoty - {0} {1} {2:F2} + - {0} {1} {2:F2} Network Error @@ -253,10 +253,10 @@ Set billing address: {0} - {0}/{1} {2} {3:F2} {4} + - {0}/{1} {2} {3:F2} {4} - {0}/{1}: {2} + - {0}: {1} Store page not found diff --git a/ASFEnhance/Localization/Langs.resx b/ASFEnhance/Localization/Langs.resx index ca7e3f8b..dcad7ea4 100644 --- a/ASFEnhance/Localization/Langs.resx +++ b/ASFEnhance/Localization/Langs.resx @@ -130,13 +130,13 @@ 响应为空 - {0}: 类型无效 [SUB|BUNDLE] + - {0}: 类型无效 [SUB|BUNDLE] 购物车是空的 - {0} {1} {2:F2} + - {0} {1} {2:F2} 网络错误 @@ -253,10 +253,10 @@ 结算货币设置: {0} - {0}/{1} {2} {3:F2} {4} + - {0}/{1} {2} {3:F2} {4} - {0}/{1}: {2} + - {0}: {1} 未找到商店页 diff --git a/ASFEnhance/Localization/Langs.zh-Hans.resx b/ASFEnhance/Localization/Langs.zh-Hans.resx index b8755941..390bcd92 100644 --- a/ASFEnhance/Localization/Langs.zh-Hans.resx +++ b/ASFEnhance/Localization/Langs.zh-Hans.resx @@ -130,13 +130,13 @@ 响应为空 - {0}: 类型无效 [SUB|BUNDLE] + - {0}: 类型无效 [SUB|BUNDLE] 购物车是空的 - {0} {1} {2:F2} + - 0} {1} {2:F2} 网络错误 @@ -253,10 +253,10 @@ 结算货币设置: {0} - {0}/{1} {2} {3:F2} {4} + - {0}/{1} {2} {3:F2} {4} - {0}/{1}: {2} + - {0}: {1} 未找到商店页 diff --git a/ASFEnhance/Store/Command.cs b/ASFEnhance/Store/Command.cs index 305f7328..69b0157e 100644 --- a/ASFEnhance/Store/Command.cs +++ b/ASFEnhance/Store/Command.cs @@ -7,8 +7,9 @@ using ASFEnhance.Localization; using SteamKit2; using System.Text; -using static ASFEnhance.Store.Response; using static ASFEnhance.Utils; +using static ASFEnhance.Data.SteamGameID; +using static ASFEnhance.Store.Response; namespace ASFEnhance.Store { @@ -35,14 +36,18 @@ internal static class Command string walletCurrency = bot.WalletCurrency != ECurrencyCode.Invalid ? bot.WalletCurrency.ToString() : Langs.WalletAreaUnknown; + if (CurrencyHelper.Currency2Symbol.ContainsKey(walletCurrency)) + { + walletCurrency = CurrencyHelper.Currency2Symbol[walletCurrency]; + } + Dictionary gameIDs = FetchGameIDs(query, SteamGameIDType.App); StringBuilder response = new(); + response.AppendLine(bot.FormatBotResponse(Langs.MultipleLineResult)); foreach (KeyValuePair item in gameIDs) { - if (response.Length != 0) { response.AppendLine(); } - string input = item.Key; SteamGameID gameID = item.Value; @@ -52,17 +57,15 @@ internal static class Command case SteamGameIDType.Sub: case SteamGameIDType.Bundle: - string type = gameID.GameType.ToString(); - GameStorePageResponse? storeResponse = await WebRequest.GetStoreSubs(bot, gameID).ConfigureAwait(false); if (storeResponse.SubDatas.Count == 0) { - response.AppendLine(bot.FormatBotResponse(string.Format(Langs.StoreItemHeader, type, gameID, storeResponse.GameName))); + response.AppendLine(string.Format(Langs.StoreItemHeader, gameID, storeResponse.GameName)); } else { - response.AppendLine(bot.FormatBotResponse(string.Format(Langs.StoreItemHeader, type, gameID, storeResponse.GameName))); + response.AppendLine(string.Format(Langs.StoreItemHeader, gameID, storeResponse.GameName)); foreach (SingleSubData sub in storeResponse.SubDatas) { @@ -76,7 +79,8 @@ internal static class Command break; } } - return response.Length > 0 ? response.ToString() : null; + + return response.ToString(); } /// diff --git a/ASFEnhance/Store/Response.cs b/ASFEnhance/Store/Response.cs index a7245eaa..f6b09872 100644 --- a/ASFEnhance/Store/Response.cs +++ b/ASFEnhance/Store/Response.cs @@ -34,6 +34,11 @@ public SingleSubData(bool bundle = false, uint subID = 0, string name = "", uint this.Name = name; this.Price = price; } + + public override string ToString() + { + return base.ToString(); + } } /// diff --git a/ASFEnhance/Utils.cs b/ASFEnhance/Utils.cs index 4053367d..423f472b 100644 --- a/ASFEnhance/Utils.cs +++ b/ASFEnhance/Utils.cs @@ -82,7 +82,7 @@ internal static ulong SteamID2Steam32(ulong steamID) /// /// /// - internal static Dictionary 匹(string query) + internal static Dictionary FetchGameIDs(string query) { return FetchGameIDs(query, SteamGameIDType.App); } @@ -142,7 +142,7 @@ internal static Dictionary FetchGameIDs(string query, Steam /// /// /// - internal static Dictionary FetchItemIDs(string query) + internal static Dictionary FetchItemIDs(string query) { Dictionary result = new(); @@ -152,7 +152,7 @@ internal static Dictionary FetchItemIDs(string query) { if (uint.TryParse(entry, out uint itemID) && (itemID > 0)) { - result.Add(entry, new(SteamGameIDType.Item, itemID)); + result.Add(entry, new(SteamGameIDType.Item, itemID)); } else {