Skip to content

Commit

Permalink
feat 新增 PHONESUFFIX 命令
Browse files Browse the repository at this point in the history
  • Loading branch information
chr233 committed Jun 19, 2024
1 parent 8de0a6b commit 1cb61dd
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 4 deletions.
9 changes: 6 additions & 3 deletions ASFEnhance/ASFEnhance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@
using ArchiSteamFarm.Plugins.Interfaces;
using ArchiSteamFarm.Steam;
using ArchiSteamFarm.Web.GitHub;
using ArchiSteamFarm.Web.GitHub.Data;
using ASFEnhance.Data.Plugin;
using System.ComponentModel;
using System.Composition;
using System.Globalization;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using static ArchiSteamFarm.Storage.GlobalConfig;
using static SteamKit2.GC.Dota.Internal.CMsgDOTALeague;

namespace ASFEnhance;

Expand Down Expand Up @@ -362,6 +359,9 @@ public Task OnLoaded()
"CML" when access >= EAccess.Operator =>
Account.Command.ResponseCheckMarketLimit(bot),

"PHONESUFFIX" when access >= EAccess.Operator =>
Account.Command.ResponseGetPhoneSuffix(bot),

//Cart
"CART" or
"C" when access >= EAccess.Operator =>
Expand Down Expand Up @@ -652,6 +652,9 @@ public Task OnLoaded()
"CML" when access >= EAccess.Operator =>
Account.Command.ResponseCheckMarketLimit(Utilities.GetArgsAsText(args, 1, ",")),

"PHONESUFFIX" when access >= EAccess.Operator =>
Account.Command.ResponseGetPhoneSuffix(Utilities.GetArgsAsText(args, 1, ",")),

//Cart
"CART" or
"C" when access >= EAccess.Operator =>
Expand Down
46 changes: 46 additions & 0 deletions ASFEnhance/Account/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1347,4 +1347,50 @@ private static string NotificationTargetToString(NotificationTarget target)

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

/// <summary>
/// 检查市场限制
/// </summary>
/// <param name="bot"></param>
/// <param name="query"></param>
/// <param name="privacy"></param>
/// <returns></returns>
internal static async Task<string?> ResponseGetPhoneSuffix(Bot bot)
{
if (!bot.IsConnectedAndLoggedOn)
{
return bot.FormatBotResponse(Strings.BotNotConnected);
}

var response = await WebRequest.GetPhoneSuffix(bot).ConfigureAwait(false);
return bot.FormatBotResponse(response ?? Langs.GetPhoneSuffixFailed);
}

/// <summary>
/// 检查市场限制 (多个Bot)
/// </summary>
/// <param name="botNames"></param>
/// <param name="query"></param>
/// <param name="privacy"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
internal static async Task<string?> ResponseGetPhoneSuffix(string botNames)
{
if (string.IsNullOrEmpty(botNames))
{
throw new ArgumentNullException(nameof(botNames));
}

var bots = Bot.GetBots(botNames);

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

var results = await Utilities.InParallel(bots.Select(bot => ResponseGetPhoneSuffix(bot))).ConfigureAwait(false);
var responses = new List<string?>(results.Where(result => !string.IsNullOrEmpty(result)));

return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null;
}
}
23 changes: 23 additions & 0 deletions ASFEnhance/Account/WebRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,11 @@ internal static async Task<bool> ToggleAppPrivacy(Bot bot, List<uint> appIds, bo
return response;
}

/// <summary>
/// 获取市场是否受限
/// </summary>
/// <param name="bot"></param>
/// <returns></returns>
internal static async Task<bool?> GetIfMarketLimited(Bot bot)
{
var request = new Uri(SteamCommunityURL, "/market/");
Expand All @@ -501,4 +506,22 @@ internal static async Task<bool> ToggleAppPrivacy(Bot bot, List<uint> appIds, bo
return false;
}
}

/// <summary>
/// 获取电话号码后缀
/// </summary>
/// <param name="bot"></param>
/// <returns></returns>
internal static async Task<string?> GetPhoneSuffix(Bot bot)
{
var request = new Uri(SteamStoreURL, $"/phone/manage?l={Langs.Language}");
var response = await bot.ArchiWebHandler.UrlGetToHtmlDocumentWithSession(request).ConfigureAwait(false);

if (response?.Content == null)
{
return null;
}

return response.Content.QuerySelector("div.phone_header_description>span")?.TextContent?.Trim();
}
}
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>2.1.8.2</Version>
<Version>2.1.8.3</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down

0 comments on commit 1cb61dd

Please sign in to comment.