From 0f2ef9fd67991bc5209b31fabab696b6e534bd3d Mon Sep 17 00:00:00 2001 From: Chr_ Date: Sat, 26 Jun 2021 14:04:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90EVENT=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ASFEnhance/ASFEnhance.cs | 2 +- ASFEnhance/ASFEnhance.csproj | 4 +- ASFEnhance/Command.cs | 57 +++++++++++++----------- ASFEnhance/Response.cs | 10 +++++ ASFEnhance/WebRequest.cs | 84 +++++++++++++++++++++++++++++++++--- 5 files changed, 123 insertions(+), 34 deletions(-) diff --git a/ASFEnhance/ASFEnhance.cs b/ASFEnhance/ASFEnhance.cs index 88f84408..d4dfc7d0 100644 --- a/ASFEnhance/ASFEnhance.cs +++ b/ASFEnhance/ASFEnhance.cs @@ -17,7 +17,7 @@ public void OnLoaded() { Version version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; - ASF.ArchiLogger.LogGenericInfo(string.Format("欢迎使用 ASFEnhance {0}.{1}.{2}.{3}", version.Major, version.Minor, version.Build, version.Revision)); + ASF.ArchiLogger.LogGenericInfo(string.Format("欢迎使用 ASFEnhance {0}.{1}.{2} [{3}]", version.Major, version.Minor, version.Build, version.Revision)); ASF.ArchiLogger.LogGenericInfo("作者 Chr_, 联系方式 chr@chrxw.com"); } diff --git a/ASFEnhance/ASFEnhance.csproj b/ASFEnhance/ASFEnhance.csproj index 425e608d..a0a7dd76 100644 --- a/ASFEnhance/ASFEnhance.csproj +++ b/ASFEnhance/ASFEnhance.csproj @@ -11,9 +11,9 @@ true net5.0 true - 1.5.0.30 + 1.5.1.40 AGPL-3.0 - 1.5.0.30 + 1.5.1.40 false diff --git a/ASFEnhance/Command.cs b/ASFEnhance/Command.cs index 3cf7c364..3a969bd6 100644 --- a/ASFEnhance/Command.cs +++ b/ASFEnhance/Command.cs @@ -1,17 +1,15 @@ -using System; -using System.Collections.Generic; -using System.Composition; -using System.Globalization; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using ArchiSteamFarm.Core; using ArchiSteamFarm.Localization; -using ArchiSteamFarm.Plugins.Interfaces; using ArchiSteamFarm.Steam; using ArchiSteamFarm.Steam.Interaction; using ArchiSteamFarm.Steam.Storage; using SteamKit2; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; using static Chrxw.ASFEnhance.Response; namespace Chrxw.ASFEnhance @@ -122,8 +120,8 @@ internal class Command // 查看插件版本 private static string ResponseASFEnhanceVersion() { - string version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); - return string.Format("ASFEnhance {0}", version); + Version version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; + return string.Format("ASFEnhance {0}.{1}.{2} [{3}]", version.Major, version.Minor, version.Build, version.Revision); } // 提取KEY private static string? ResponseExtractKeys(string message) @@ -633,16 +631,16 @@ private static string ResponseASFEnhanceVersion() } //夏促任务 - private static async Task ResponseSellEvent(Bot bot, ulong steamID, string query) + private static async Task ResponseSellEvent(Bot bot, ulong steamID, string choose) { if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { throw new ArgumentOutOfRangeException(nameof(steamID)); } - if (string.IsNullOrEmpty(query)) + if (string.IsNullOrEmpty(choose)) { - throw new ArgumentNullException(nameof(query)); + throw new ArgumentNullException(nameof(choose)); } if (!bot.HasAccess(steamID, BotConfig.EAccess.Operator)) @@ -655,26 +653,37 @@ private static string ResponseASFEnhanceVersion() return FormatBotResponse(bot, Strings.BotNotConnected); } - string[] entries = query.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); + string[] entries = choose.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); + + List intChoose = new(); foreach (string entry in entries) { uint choice; - int index = entry.IndexOf('/', StringComparison.Ordinal); - - if (uint.TryParse(entry, out choice) && (choice > 0) && (choice < 3)) - { - //type = "APP"; - } - else + if (uint.TryParse(entry, out choice) && (choice == 1 || choice == 2)) { - //response.AppendLine(FormatBotResponse(bot, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsInvalid, entry))); - continue; + intChoose.Add(choice); + if (intChoose.Count >= 14) + { + break; + } } + } + + if (intChoose.Count != 14) + { + return FormatBotResponse(bot, "选项值错误,请参考原帖"); + } + + string? badgeName = await WebRequest.SummerEvent(bot, intChoose.ToArray()).ConfigureAwait(false); + if (string.IsNullOrEmpty(badgeName)) + { + return FormatBotResponse(bot, string.Format("读取夏促徽章出错: {0}", badgeName)); } - return null; + + return FormatBotResponse(bot, string.Format("当前夏促徽章: {0}", badgeName)); } //夏促任务(多个Bot) private static async Task ResponseSellEvent(ulong steamID, string botNames, string query) diff --git a/ASFEnhance/Response.cs b/ASFEnhance/Response.cs index a806e909..f37227bc 100644 --- a/ASFEnhance/Response.cs +++ b/ASFEnhance/Response.cs @@ -68,5 +68,15 @@ public SubData(bool bundle = false, uint subID = 0, string name = "", uint price this.price = price; } } + + internal enum SummeryBadges + { + none, + mmfcz, + xftlz, + xxkxj, + lyxjs, + yldzt + } } } diff --git a/ASFEnhance/WebRequest.cs b/ASFEnhance/WebRequest.cs index 5b9fefc7..0a4cb43c 100644 --- a/ASFEnhance/WebRequest.cs +++ b/ASFEnhance/WebRequest.cs @@ -1,4 +1,5 @@ -using ArchiSteamFarm.Core; +using AngleSharp.Dom; +using ArchiSteamFarm.Core; using ArchiSteamFarm.Localization; using ArchiSteamFarm.Steam; using ArchiSteamFarm.Steam.Data; @@ -7,7 +8,6 @@ using SteamKit2; using System; using System.Collections.Generic; -using System.IO; using System.Threading.Tasks; using static Chrxw.ASFEnhance.Response; @@ -182,18 +182,88 @@ internal static async Task RemoveWishlist(Bot bot, uint gameID) } //夏促任务 - internal static async Task PostSemmerEvent(Bot bot) + internal static async Task SummerEvent(Bot bot, uint[] choose) { - return false; + + string? sb = await GetSummerBadge(bot).ConfigureAwait(false); + + if (sb != null) + { + return sb; + } + + uint genre = 1; + foreach (uint choice in choose) + { + await SelectSummerChoice(bot, genre++, choice).ConfigureAwait(false); + } + + return await GetSummerBadge(bot).ConfigureAwait(false); } - //手动探索队列 - internal static async Task DiscoveryQueue(Bot bot) + //获取夏促徽章 + private static async Task GetSummerBadge(Bot bot) { - return false; + Uri request = new(SteamCommunityURL, string.Format("/profiles/{0}/?l=schinese", bot.SteamID.ToString())); + + HtmlDocumentResponse? response = await bot.ArchiWebHandler.UrlGetToHtmlDocumentWithSession(request).ConfigureAwait(false); + + if (response == null) + { + bot.ArchiLogger.LogNullError(nameof(response)); + return null; + } + + IElement? eleBadge = response.Content.SelectSingleNode("//div[@class='profile_count_link_preview']/div[1]"); + + if (eleBadge == null) + { + bot.ArchiLogger.LogNullError(nameof(eleBadge)); + return null; + } + + string tooltip = eleBadge.GetAttribute("data-tooltip-html").Substring(0, 5) ?? "读取徽章出错"; + + switch (tooltip) + { + case "蒙面复仇者": + case "先锋探路者": + case "猩猩科学家": + case "灵异学教授": + case "幽灵大侦探": + return tooltip; + default: + bot.ArchiLogger.LogGenericError(string.Format("tooltip = {0}", tooltip)); + return null; + } } + //夏促选择选项 + private static async Task SelectSummerChoice(Bot bot, uint genre, uint choice) + { + Uri request = new(SteamStoreURL, "/promotion/ajaxclaimstickerforgenre"); + + string? sessionID = bot.ArchiWebHandler.WebBrowser.CookieContainer.GetCookieValue(SteamStoreURL, "sessionid"); + + if (string.IsNullOrEmpty(sessionID)) + { + bot.ArchiLogger.LogNullError(nameof(sessionID)); + return false; + } + + Dictionary data = new(3, StringComparer.Ordinal) + { + { "genre", genre.ToString() }, + { "choice", choice.ToString() }, + { "sessionid", sessionID! } + }; + + await bot.ArchiWebHandler.UrlPostWithSession(request, data: data).ConfigureAwait(false); + + return true; + } internal static Uri SteamStoreURL => ArchiWebHandler.SteamStoreURL; + internal static Uri SteamCommunityURL => ArchiWebHandler.SteamCommunityURL; } }