Skip to content

Commit

Permalink
feat 新增 DL2 命令, 可获取消逝的光芒2相关装饰品
Browse files Browse the repository at this point in the history
  • Loading branch information
chr233 committed Nov 11, 2022
1 parent 8aa8cf7 commit e6891e7
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 8 deletions.
6 changes: 6 additions & 0 deletions ASFEnhance/ASFEnhance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ private async Task<string> ResponseCommand(Bot bot, EAccess access, string messa

case "SIM4" when access >= EAccess.Operator:
return await Event.Command.ResponseSim4(bot).ConfigureAwait(false);

case "DL2" when access >= EAccess.Operator:
return await Event.Command.ResponseDL2(bot).ConfigureAwait(false);

//Shortcut
case "P":
Expand Down Expand Up @@ -313,6 +316,9 @@ private async Task<string> ResponseCommand(Bot bot, EAccess access, string messa
case "SIM4" when access >= EAccess.Operator:
return await Event.Command.ResponseSim4(Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false);

case "DL2" when access >= EAccess.Operator:
return await Event.Command.ResponseDL2(Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false);

//Shortcut
case "AL":
return await bot.Commands.Response(access, "ADDLICENSE " + Utilities.GetArgsAsText(message, 1), steamID).ConfigureAwait(false);
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: CLSCompliant(false)]
[assembly: AssemblyVersion("1.6.17.2")]
[assembly: AssemblyFileVersion("1.6.17.2")]
[assembly: AssemblyVersion("1.6.18.0")]
[assembly: AssemblyFileVersion("1.6.18.0")]

[assembly: AssemblyCopyright("Copyright © 2022 Chr_")]
[assembly: AssemblyProduct("ASFEnhance")]
Expand Down
60 changes: 57 additions & 3 deletions ASFEnhance/Event/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal static class Command
return bot.FormatBotResponse(Strings.BotNotConnected);
}

string token = await WebRequest.FetchEventToken(bot).ConfigureAwait(false);
string token = await WebRequest.FetchEventToken(bot, "simscelebrationsale").ConfigureAwait(false);
if (token == null)
{
return bot.FormatBotResponse(Langs.NetworkError);
Expand All @@ -38,10 +38,9 @@ internal static class Command
}

/// <summary>
/// 获取活动徽章 (多个Bot)
/// 获取SIM4贴纸 (多个Bot)
/// </summary>
/// <param name="botNames"></param>
/// <param name="gruopID"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
internal static async Task<string?> ResponseSim4(string botNames)
Expand All @@ -64,5 +63,60 @@ internal static class Command

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

/// <summary>
/// 获取DL2贴纸 11.11 - ?
/// </summary>
/// <param name="bot"></param>
/// <returns></returns>
internal static async Task<string?> ResponseDL2(Bot bot)
{
if (!bot.IsConnectedAndLoggedOn)
{
return bot.FormatBotResponse(Strings.BotNotConnected);
}

string token = await WebRequest.FetchEventToken(bot, "dyinglight").ConfigureAwait(false);
if (token == null)
{
return bot.FormatBotResponse(Langs.NetworkError);
}

uint[] door_indexs = { 1, 3, 4, 5, 2 };

foreach (uint index in door_indexs)
{
await WebRequest.DoEventTask(bot, token, index).ConfigureAwait(false);
}

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

/// <summary>
/// 获取DL2贴纸 (多个Bot)
/// </summary>
/// <param name="botNames"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
internal static async Task<string?> ResponseDL2(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 => ResponseDL2(bot))).ConfigureAwait(false);

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

return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null;
}
}
}
8 changes: 5 additions & 3 deletions ASFEnhance/Event/WebRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ internal static class WebRequest
/// 模拟探索队列
/// </summary>
/// <param name="bot"></param>
/// <param name="token"></param>
/// <param name="clan_accountid"></param>
/// <param name="door_index"></param>
/// <returns></returns>
internal static async Task DoEventTask(Bot bot, string clan_accountid, uint door_index)
{
Expand All @@ -32,10 +33,11 @@ internal static async Task DoEventTask(Bot bot, string clan_accountid, uint door
/// 获取Token
/// </summary>
/// <param name="bot"></param>
/// <param name="salePage"></param>
/// <returns></returns>
internal static async Task<string?> FetchEventToken(Bot bot)
internal static async Task<string?> FetchEventToken(Bot bot,string salePage)
{
Uri request = new(SteamStoreURL, "/sale/simscelebrationsale?tab=2");
Uri request = new(SteamStoreURL, $"/sale/{salePage}");

var response = await bot.ArchiWebHandler.UrlGetToHtmlDocumentWithSession(request).ConfigureAwait(false);

Expand Down

0 comments on commit e6891e7

Please sign in to comment.