Skip to content

Commit

Permalink
完成EVENT命令
Browse files Browse the repository at this point in the history
  • Loading branch information
chr233 committed Jun 26, 2021
1 parent c498d33 commit 0f2ef9f
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 34 deletions.
2 changes: 1 addition & 1 deletion ASFEnhance/ASFEnhance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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_, 联系方式 [email protected]");
}

Expand Down
4 changes: 2 additions & 2 deletions ASFEnhance/ASFEnhance.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetFramework>net5.0</TargetFramework>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<AssemblyVersion>1.5.0.30</AssemblyVersion>
<AssemblyVersion>1.5.1.40</AssemblyVersion>
<PackageLicenseExpression>AGPL-3.0</PackageLicenseExpression>
<FileVersion>1.5.0.30</FileVersion>
<FileVersion>1.5.1.40</FileVersion>
<EnforceCodeStyleInBuild>false</EnforceCodeStyleInBuild>
<PackageLicenseFile></PackageLicenseFile>
</PropertyGroup>
Expand Down
57 changes: 33 additions & 24 deletions ASFEnhance/Command.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -633,16 +631,16 @@ private static string ResponseASFEnhanceVersion()
}

//夏促任务
private static async Task<string?> ResponseSellEvent(Bot bot, ulong steamID, string query)
private static async Task<string?> 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))
Expand All @@ -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<uint> 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<string?> ResponseSellEvent(ulong steamID, string botNames, string query)
Expand Down
10 changes: 10 additions & 0 deletions ASFEnhance/Response.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
84 changes: 77 additions & 7 deletions ASFEnhance/WebRequest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ArchiSteamFarm.Core;
using AngleSharp.Dom;
using ArchiSteamFarm.Core;
using ArchiSteamFarm.Localization;
using ArchiSteamFarm.Steam;
using ArchiSteamFarm.Steam.Data;
Expand All @@ -7,7 +8,6 @@
using SteamKit2;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using static Chrxw.ASFEnhance.Response;

Expand Down Expand Up @@ -182,18 +182,88 @@ internal static async Task<bool> RemoveWishlist(Bot bot, uint gameID)
}

//夏促任务
internal static async Task<bool?> PostSemmerEvent(Bot bot)
internal static async Task<string?> 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<bool?> DiscoveryQueue(Bot bot)
//获取夏促徽章
private static async Task<string?> 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<bool> 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<string, string> 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;
}
}

0 comments on commit 0f2ef9f

Please sign in to comment.