Skip to content

Commit

Permalink
新增 EVENTTHEME 命令
Browse files Browse the repository at this point in the history
  • Loading branch information
chr233 committed Jun 24, 2022
1 parent 984dfb6 commit 3f2548f
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 11 deletions.
6 changes: 6 additions & 0 deletions ASFEnhance/ASFEnhance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ public Task OnLoaded()
case "EVENT" when access >= EAccess.Operator:
case "E" when access >= EAccess.Operator:
return await Event.Command.ResponseEvent(bot).ConfigureAwait(false);
case "EVENTTHEME" when access >= EAccess.Operator:
case "ET" when access >= EAccess.Operator:
return await Event.Command.ResponseEventTheme(bot).ConfigureAwait(false);

//Shortcut
case "P":
Expand Down Expand Up @@ -262,6 +265,9 @@ public Task OnLoaded()
case "EVENT" when access >= EAccess.Operator:
case "E" when access >= EAccess.Operator:
return await Event.Command.ResponseEvent(Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false);
case "EVENTTHEME" when access >= EAccess.Operator:
case "ET" when access >= EAccess.Operator:
return await Event.Command.ResponseEventTheme(Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false);

//Shortcut
case "AL":
Expand Down
4 changes: 2 additions & 2 deletions ASFEnhance/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Reflection;

[assembly: System.CLSCompliant(false)]
[assembly: AssemblyVersion("1.6.6.613")]
[assembly: AssemblyFileVersion("1.6.6.613")]
[assembly: AssemblyVersion("1.6.6.621")]
[assembly: AssemblyFileVersion("1.6.6.621")]

[assembly: AssemblyCopyright("Copyright © 2022 Chr_")]
[assembly: AssemblyProduct("ASFEnhance")]
Expand Down
60 changes: 56 additions & 4 deletions ASFEnhance/Event/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace ASFEnhance.Event
internal static class Command
{
/// <summary>
/// 夏促活动
/// 获取夏促活动徽章
/// </summary>
/// <param name="bot"></param>
/// <param name="gruopID"></param>
Expand All @@ -31,7 +31,7 @@ internal static class Command
return bot.FormatBotResponse(Langs.NetworkError);
}

var a1 = await WebRequest.AjaxOpenDoor(bot, userInfo).ConfigureAwait(false);
var a1 = await WebRequest.StartTask(bot, userInfo).ConfigureAwait(false);


for (int index = 0; index < 10; index++)
Expand All @@ -41,14 +41,14 @@ internal static class Command
{
continue;
}
var a2 = await WebRequest.AjaxOpenDoor(bot, userInfo, capsuleinsert, index).ConfigureAwait(false);
var a2 = await WebRequest.FinishTask(bot, userInfo, capsuleinsert, index).ConfigureAwait(false);
}

return bot.FormatBotResponse("Done!");
}

/// <summary>
/// 夏促活动 (多个Bot)
/// 获取夏促活动徽章 (多个Bot)
/// </summary>
/// <param name="botNames"></param>
/// <param name="gruopID"></param>
Expand All @@ -74,5 +74,57 @@ internal static class Command

return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null;
}

/// <summary>
/// 获取夏促活动主题
/// </summary>
/// <param name="bot"></param>
/// <param name="gruopID"></param>
/// <returns></returns>
internal static async Task<string?> ResponseEventTheme(Bot bot)
{
if (!bot.IsConnectedAndLoggedOn)
{
return bot.FormatBotResponse(Strings.BotNotConnected);
}

var userInfo = await WebRequest.FetUserInfo(bot).ConfigureAwait(false);
if (userInfo == null)
{
return bot.FormatBotResponse(Langs.NetworkError);
}

var a3 = await WebRequest.UnlockTheme(bot, userInfo).ConfigureAwait(false);

return bot.FormatBotResponse("Done!");
}

/// <summary>
/// 获取夏促活动主题 (多个Bot)
/// </summary>
/// <param name="botNames"></param>
/// <param name="gruopID"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
internal static async Task<string?> ResponseEventTheme(string botNames)
{
if (string.IsNullOrEmpty(botNames))
{
throw new ArgumentNullException(nameof(botNames));
}

HashSet<Bot>? bots = Bot.GetBots(botNames);

if ((bots == null) || (bots.Count == 0))
{
return FormatStaticResponse(string.Format(Strings.BotNotFound, botNames));
}

IList<string?> results = await Utilities.InParallel(bots.Select(bot => ResponseEventTheme(bot))).ConfigureAwait(false);

List<string> responses = new(results.Where(result => !string.IsNullOrEmpty(result))!);

return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null;
}
}
}
40 changes: 38 additions & 2 deletions ASFEnhance/Event/WebRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ internal static class WebRequest
}
}

internal static async Task<AjaxOpenDoorResponse?> AjaxOpenDoor(Bot bot, UserInfoResponse userInfo)
/// <summary>
/// 开始徽章任务
/// </summary>
/// <param name="bot"></param>
/// <param name="userInfo"></param>
/// <returns></returns>
internal static async Task<AjaxOpenDoorResponse?> StartTask(Bot bot, UserInfoResponse userInfo)
{
Uri request = new(SteamStoreURL, "/saleaction/ajaxopendoor");
Uri referer = new(SteamStoreURL, "/sale/clorthax_quest");
Expand All @@ -60,7 +66,15 @@ internal static class WebRequest
return response?.Content;
}

internal static async Task<AjaxOpenDoorResponse?> AjaxOpenDoor(Bot bot, UserInfoResponse userInfo, CapsuleinsertResponse capsuleinsert, int index)
/// <summary>
/// 解锁徽章任务
/// </summary>
/// <param name="bot"></param>
/// <param name="userInfo"></param>
/// <param name="capsuleinsert"></param>
/// <param name="index"></param>
/// <returns></returns>
internal static async Task<AjaxOpenDoorResponse?> FinishTask(Bot bot, UserInfoResponse userInfo, CapsuleinsertResponse capsuleinsert, int index)
{
Uri request = new(SteamStoreURL, "/saleaction/ajaxopendoor");
Uri referer = new(SteamStoreURL, $"/category/{UriList[index]}/");
Expand All @@ -77,6 +91,28 @@ internal static class WebRequest
return response?.Content;
}

/// <summary>
/// 全部解锁后获取特殊主题
/// </summary>
/// <param name="bot"></param>
/// <param name="userInfo"></param>
/// <returns></returns>
internal static async Task<AjaxOpenDoorResponse?> UnlockTheme(Bot bot, UserInfoResponse userInfo)
{
Uri request = new(SteamStoreURL, "/saleaction/ajaxopendoor");
Uri referer = new(SteamStoreURL, "/sale/clorthax_quest");

Dictionary<string, string> data = new(5) {
{ "authwgtoken", userInfo.AuthwgToken },
{ "door_index", "11" },
{ "clan_accountid", "39049601" },
};

var response = await bot.ArchiWebHandler.UrlPostToJsonObjectWithSession<AjaxOpenDoorResponse>(request, data: data, referer: referer).ConfigureAwait(false);

return response?.Content;
}

private static List<string> UriList { get; } = new() {
"category/arcade_rhythm",
"category/strategy_cities_settlements",
Expand Down
6 changes: 3 additions & 3 deletions ASFEnhance/Explorer/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ internal static class Command
/// <param name="bot"></param>
/// <param name="gruopID"></param>
/// <returns></returns>
internal static async Task<string?> ResponseExploreDiscoveryQueue(Bot bot)
internal static Task<string?> ResponseExploreDiscoveryQueue(Bot bot)
{
if (!bot.IsConnectedAndLoggedOn)
{
return bot.FormatBotResponse(Strings.BotNotConnected);
return Task.FromResult(bot.FormatBotResponse(Strings.BotNotConnected));
}

var steamSaleEvent = Type.GetType("ArchiSteamFarm.Steam.Integration.SteamSaleEvent,ArchiSteamFarm");
Expand All @@ -36,7 +36,7 @@ internal static class Command

saleEventTimer.Change(TimeSpan.FromSeconds(5), TimeSpan.FromHours(8.1));

return bot.FormatBotResponse(Langs.ExplorerStart);
return Task.FromResult(bot.FormatBotResponse(Langs.ExplorerStart));
}

/// <summary>
Expand Down

0 comments on commit 3f2548f

Please sign in to comment.