Skip to content

Commit

Permalink
add #216
Browse files Browse the repository at this point in the history
  • Loading branch information
chr233 committed Feb 18, 2024
1 parent f4ffcc2 commit 4122a24
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 7 deletions.
10 changes: 9 additions & 1 deletion ASFEnhance/ASFEnhance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ public Task OnLoaded()

"PROFILELINK" or
"PFL" when access >= EAccess.FamilySharing =>
Task.FromResult(Profile.Command.ResponseGetProfileLink(bot)),
Profile.Command.ResponseGetProfileLink(bot),

"RANDOMGAMEAVATAR" or
"RGA" when access >= EAccess.Master =>
Expand All @@ -454,6 +454,10 @@ public Task OnLoaded()
"DCU" when access >= EAccess.Master =>
Profile.Command.ResponseEditCustomUrl(bot, null),

"BALANCEINFO" or
"BI" when access >= EAccess.Operator =>
Profile.Command.ResponseBalanceInfo(bot),

//DevFuture
"COOKIES" when Config.DevFeature && access >= EAccess.Owner =>
Task.FromResult(DevFeature.Command.ResponseGetCookies(bot)),
Expand Down Expand Up @@ -850,6 +854,10 @@ public Task OnLoaded()
"DCU" when access >= EAccess.Master =>
Profile.Command.ResponseEditCustomUrl(Utilities.GetArgsAsText(args, 1, ","), null),

"BALANCEINFO" or
"BI" when access >= EAccess.Operator =>
Profile.Command.ResponseBalanceInfo(Utilities.GetArgsAsText(args, 1, ",")),

//Store
"APPDETAIL" or
"AD" when argLength > 2 && access >= EAccess.Operator =>
Expand Down
61 changes: 58 additions & 3 deletions ASFEnhance/Profile/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,29 @@ internal static class Command
/// </summary>
/// <param name="bot"></param>
/// <returns></returns>
internal static string? ResponseGetProfileLink(Bot bot)
internal static async Task<string?> ResponseGetProfileLink(Bot bot)
{
if (!bot.IsConnectedAndLoggedOn)
{
return bot.FormatBotResponse(Strings.BotNotConnected);
}

var profileLink = new Uri(SteamCommunityURL + $"profiles/{bot.SteamID}");
var absPath = $"/profiles/{bot.SteamID}";
var customPath = await bot.GetProfileLink().ConfigureAwait(false);

return bot.FormatBotResponse(profileLink.ToString());
var sb = new StringBuilder();

if (string.Compare(absPath, customPath, StringComparison.OrdinalIgnoreCase) != 0)
{
sb.AppendLine(bot.FormatBotResponse(new Uri(SteamCommunityURL, absPath).ToString()));
sb.AppendLine(bot.FormatBotResponse(new Uri(SteamCommunityURL, customPath).ToString()));
}
else
{
sb.AppendLine(bot.FormatBotResponse(new Uri(SteamCommunityURL, absPath).ToString()));
}

return sb.ToString();
}

/// <summary>
Expand Down Expand Up @@ -822,4 +835,46 @@ internal static class Command

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

/// <summary>
/// 获取钱包
/// </summary>
/// <param name="bot"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
internal static async Task<string?> ResponseBalanceInfo(Bot bot)
{
if (!bot.IsConnectedAndLoggedOn)
{
return bot.FormatBotResponse(Strings.BotNotConnected);
}

return await WebRequest.GetAccountBalanceInfo(bot).ConfigureAwait(false);
}

/// <summary>
/// 获取钱包 (多个Bot)
/// </summary>
/// <param name="botNames"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
internal static async Task<string?> ResponseBalanceInfo(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 => ResponseBalanceInfo(bot))).ConfigureAwait(false);
var responses = new List<string?>(results.Where(result => !string.IsNullOrEmpty(result)));

return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null;
}
}
30 changes: 30 additions & 0 deletions ASFEnhance/Profile/WebRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,4 +339,34 @@ internal static async Task<bool> CraftBadge(Bot bot, SemaphoreSlim semaphore, ui

return response?.Content;
}

/// <summary>
/// 获取待处理余额信息
/// </summary>
/// <param name="bot"></param>
/// <returns></returns>
internal static async Task<string?> GetAccountBalanceInfo(Bot bot)
{
var request = new Uri(SteamStoreURL, $"/account/?l={Langs.Language}");

var response = await bot.ArchiWebHandler.UrlGetToHtmlDocumentWithSession(request, referer: SteamStoreURL).ConfigureAwait(false);

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

var tooltip = response.Content.QuerySelector("#header_wallet_balance>span.tooltip")?.TextContent;
if (!string.IsNullOrEmpty(tooltip) && bot.WalletBalanceDelayed > 0)
{
var match = RegexUtils.MatchWalletTooltips().Match(tooltip);
var time = match.Success ? " " + match.Groups[1].Value : null;
return bot.FormatBotResponse(Langs.WalletInfo4, bot.WalletBalance / 100.0, bot.WalletBalanceDelayed / 100.0, time, bot.WalletCurrency);
}
else
{
return bot.FormatBotResponse(Langs.WalletInfo2, bot.WalletBalance / 100.0, bot.WalletCurrency);
}
}

}
3 changes: 3 additions & 0 deletions ASFEnhance/RegexUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,7 @@ internal static partial class RegexUtils

[GeneratedRegex(@"""webapi_token"":""([^""]+)""")]
public static partial Regex MatchWebApiToken();

[GeneratedRegex(@"(?:\(|()([^))]+)(?:\)|))")]
public static partial Regex MatchWalletTooltips();
}
2 changes: 1 addition & 1 deletion ArchiSteamFarm
Submodule ArchiSteamFarm updated 245 files
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.0.12.1</Version>
<Version>2.0.13.0</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion wiki
Submodule wiki updated from d3c1e9 to c73a94

0 comments on commit 4122a24

Please sign in to comment.