Skip to content

Commit 0c7f62a

Browse files
committed
feat 新增 SETPROFILETHEME 命令
feat 新增 SETPROFILEMODIFIER 命令
1 parent dc2b2ca commit 0c7f62a

File tree

8 files changed

+238
-132
lines changed

8 files changed

+238
-132
lines changed

ASFEnhance.IPC/ASFEnhance.IPC.csproj

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@
55
</PropertyGroup>
66

77
<ItemGroup>
8-
<ProjectReference Include="..\ArchiSteamFarm\ArchiSteamFarm\ArchiSteamFarm.csproj" />
9-
<ProjectReference Include="..\ASFEnhance\ASFEnhance.csproj" />
8+
<ProjectReference Include="..\ArchiSteamFarm\ArchiSteamFarm\ArchiSteamFarm.csproj">
9+
<Private>False</Private>
10+
<ExcludeAssets>all</ExcludeAssets>
11+
</ProjectReference>
12+
<ProjectReference Include="..\ASFEnhance\ASFEnhance.csproj">
13+
<Private>True</Private>
14+
</ProjectReference>
1015
</ItemGroup>
1116

1217
<ItemGroup>

ASFEnhance/ASFEnhance.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,10 @@ public Task OnLoaded()
411411
"BI" when access >= EAccess.Operator =>
412412
Profile.Command.ResponseBalanceInfo(bot),
413413

414+
"CLEARPROFILETHEME" or
415+
"CPT" when access >= EAccess.Master =>
416+
Profile.Command.ResponseSetProfileTheme(bot, null),
417+
414418
//Inventory
415419
"PENDINGGIFT" or
416420
"PG" when access >= EAccess.Operator =>
@@ -854,7 +858,7 @@ public Task OnLoaded()
854858
Profile.Command.ResponseSetReplayPrivacy(args[2], Utilities.GetArgsAsText(args, 3, ","), args[1]),
855859
"REPLAYPRIVACY" or
856860
"RPP" when argLength == 3 && access >= EAccess.Operator =>
857-
Profile.Command.ResponseSetReplayPrivacy(args[1], Utilities.GetArgsAsText(args, 2, ","), "2023"),
861+
Profile.Command.ResponseSetReplayPrivacy(args[1], Utilities.GetArgsAsText(args, 2, ","), "2024"),
858862
"REPLAYPRIVACY" or
859863
"RPP" when access >= EAccess.Operator =>
860864
Profile.Command.ResponseSetReplayPrivacy(bot, args[1], "2024"),
@@ -889,6 +893,31 @@ public Task OnLoaded()
889893
"BI" when access >= EAccess.Operator =>
890894
Profile.Command.ResponseBalanceInfo(Utilities.GetArgsAsText(args, 1, ",")),
891895

896+
"SETPROFILETHEME" or
897+
"SPT" when argLength == 3 && access >= EAccess.Master =>
898+
Profile.Command.ResponseSetProfileTheme(args[1], args[2]),
899+
"SETPROFILETHEME" or
900+
"SPT" when argLength == 2 && access >= EAccess.Master =>
901+
Profile.Command.ResponseSetProfileTheme(bot, args[1]),
902+
903+
"CLEARPROFILETHEME" or
904+
"CPT" when access >= EAccess.Master =>
905+
Profile.Command.ResponseSetProfileTheme(Utilities.GetArgsAsText(args, 1, ","), null),
906+
907+
"SETPROFILEMODIFIER" or
908+
"SPM" when argLength == 4 && access >= EAccess.Master =>
909+
Profile.Command.ResponseSetProfileModifier(args[1], args[2], args[3], true),
910+
"SETPROFILEMODIFIER" or
911+
"SPM" when argLength == 3 && access >= EAccess.Master =>
912+
Profile.Command.ResponseSetProfileModifier(bot, args[1], args[2], true),
913+
914+
"CLEARPROFILEMODIFIER" or
915+
"CPM" when argLength == 4 && access >= EAccess.Master =>
916+
Profile.Command.ResponseSetProfileModifier(args[1], args[2], args[3], false),
917+
"CLEARPROFILEMODIFIER" or
918+
"CPM" when argLength == 3 && access >= EAccess.Master =>
919+
Profile.Command.ResponseSetProfileModifier(bot, args[1], args[2], false),
920+
892921
//Store
893922
"SUBS" or
894923
"S" or

ASFEnhance/ASFEnhance.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</ItemGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="AngleSharp" />
11+
<PackageReference Include="AngleSharp.XPath" />
1212
<PackageReference Include="SteamKit2" IncludeAssets="compile" />
1313
<PackageReference Include="System.Composition.AttributedModel" />
1414
<PackageReference Include="System.Linq.Async" IncludeAssets="compile" />

ASFEnhance/Cart/WebRequest.cs

Lines changed: 2 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using ArchiSteamFarm.Core;
21
using ArchiSteamFarm.Helpers.Json;
32
using ArchiSteamFarm.Steam;
43
using ArchiSteamFarm.Steam.Integration;
@@ -381,129 +380,6 @@ public static class WebRequest
381380
return response2.Content;
382381
}
383382

384-
/// <summary>
385-
/// 获取数字礼品卡可用面额
386-
/// </summary>
387-
/// <param name="bot"></param>
388-
/// <returns></returns>
389-
internal static async Task<List<DigitalGiftCardOption>?> GetDigitalGiftCardOptions(Bot bot)
390-
{
391-
var request = new Uri(SteamStoreURL, "/digitalgiftcards/selectgiftcard");
392-
var response = await bot.ArchiWebHandler.UrlGetToHtmlDocumentWithSession(request).ConfigureAwait(false);
393-
394-
return HtmlParser.ParseDigitalGiftCardOptions(response);
395-
}
396-
397-
/// <summary>
398-
/// 提交礼品卡支付
399-
/// </summary>
400-
/// <param name="bot"></param>
401-
/// <param name="amount"></param>
402-
/// <returns></returns>
403-
internal static async Task<HtmlDocumentResponse?> SubmitGiftCard(Bot bot, uint amount)
404-
{
405-
var request = new Uri(SteamStoreURL, "/digitalgiftcards/submitgiftcard");
406-
var referer = new Uri(SteamStoreURL, "/digitalgiftcards/selectgiftcard");
407-
408-
var data = new Dictionary<string, string>(4, StringComparer.Ordinal)
409-
{
410-
{ "action", "add_to_cart" },
411-
{ "currency", bot.WalletCurrency.ToString() },
412-
{ "amount", amount.ToString() }
413-
};
414-
415-
var response = await bot.ArchiWebHandler
416-
.UrlPostToHtmlDocumentWithSession(request, data: data, referer: referer,
417-
session: ArchiWebHandler.ESession.PascalCase).ConfigureAwait(false);
418-
419-
return response;
420-
}
421-
422-
/// <summary>
423-
/// 初始化礼品卡付款
424-
/// </summary>
425-
/// <param name="bot"></param>
426-
/// <param name="steamId32"></param>
427-
/// <param name="method"></param>
428-
/// <returns></returns>
429-
[Obsolete("未使用")]
430-
internal static async Task<PurchaseResponse?> InitTransactionDigicalCard(Bot bot, ulong steamId32,
431-
string method = "alipay")
432-
{
433-
var request = new Uri(SteamCheckoutURL, "/checkout/inittransaction/");
434-
435-
var shoppingCartId =
436-
bot.ArchiWebHandler.WebBrowser.CookieContainer.GetCookieValue(new Uri(SteamCheckoutURL, "/checkout/"),
437-
"beginCheckoutCart");
438-
439-
if (string.IsNullOrEmpty(shoppingCartId))
440-
{
441-
if (string.IsNullOrEmpty(shoppingCartId))
442-
{
443-
bot.ArchiLogger.LogNullError(nameof(shoppingCartId));
444-
return null;
445-
}
446-
}
447-
448-
var referer = new Uri(SteamCheckoutURL, $"/checkout?cart={shoppingCartId}&purchasetype=gift");
449-
450-
var data = new Dictionary<string, string>(11, StringComparer.Ordinal)
451-
{
452-
{ "gidShoppingCart", "-1" },
453-
{ "gidReplayOfTransID", "-1" },
454-
{ "PaymentMethod", method },
455-
{ "abortPendingTransactions", "0" },
456-
{ "bHasCardInfo", "0" },
457-
{ "CardNumber", "" },
458-
{ "CardExpirationYear", "" },
459-
{ "CardExpirationMonth", "" },
460-
{ "FirstName", "" },
461-
{ "LastName", "" },
462-
{ "Address", "" },
463-
{ "AddressTwo", "" },
464-
{ "Country", "CN" },
465-
{ "City", "" },
466-
{ "State", "" },
467-
{ "PostalCode", "" },
468-
{ "Phone", "" },
469-
{ "ShippingFirstName", "" },
470-
{ "ShippingLastName", "" },
471-
{ "ShippingAddress", "" },
472-
{ "ShippingAddressTwo", "" },
473-
{ "ShippingCountry", "CN" },
474-
{ "ShippingCity", "" },
475-
{ "ShippingState", "" },
476-
{ "ShippingPostalCode", "" },
477-
{ "ShippingPhone", "" },
478-
{ "bIsGift", "1" },
479-
{ "GifteeAccountID", steamId32.ToString() },
480-
{ "GifteeEmail", "" },
481-
{ "GifteeName", Langs.GifteeName },
482-
{
483-
"GiftMessage", string.Format(Langs.GiftMessage, nameof(ASFEnhance), MyVersion.Major, MyVersion.Minor,
484-
MyVersion.Build, MyVersion.Revision)
485-
},
486-
{ "Sentiment", "祝你好运" },
487-
{ "Signature", string.Format(Langs.GiftSignature, nameof(ASFEnhance)) },
488-
{ "ScheduledSendOnDate", "0" },
489-
{ "BankAccount", "" },
490-
{ "BankCode", "" },
491-
{ "BankIBAN", "" },
492-
{ "BankBIC", "" },
493-
{ "TPBankID", "" },
494-
{ "BankAccountID", "" },
495-
{ "bSaveBillingAddress", "1" },
496-
{ "gidPaymentID", "" },
497-
{ "bUseRemainingSteamAccount", "0" },
498-
{ "bPreAuthOnly", "0" }
499-
};
500-
501-
var response = await bot.ArchiWebHandler
502-
.UrlPostToJsonObjectWithSession<PurchaseResponse>(request, data: data, referer: referer)
503-
.ConfigureAwait(false);
504-
return response?.Content;
505-
}
506-
507383
/// <summary>
508384
/// 提交充值卡支付
509385
/// </summary>
@@ -599,7 +475,7 @@ public static class WebRequest
599475
}
600476

601477
/// <summary>
602-
/// 充值卡付款
478+
/// 充值卡付款
603479
/// </summary>
604480
/// <param name="bot"></param>
605481
/// <param name="gidShoppingCart"></param>
@@ -617,7 +493,7 @@ public static class WebRequest
617493
}
618494

619495
/// <summary>
620-
/// 充值卡结算, 跳转外部支付
496+
/// 充值卡结算, 跳转外部支付
621497
/// </summary>
622498
/// <param name="bot"></param>
623499
/// <param name="gidShoppingCart"></param>

ASFEnhance/Localization/Langs.resx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,4 +1494,13 @@
14941494
<data name="WalletCodeRedeemFailed" xml:space="preserve">
14951495
<value>充值码激活失败, 代码 {0}</value>
14961496
</data>
1497+
<data name="InvalidThemeName" xml:space="preserve">
1498+
<value>themeName 无效, 仅可为 *, summer, midnight, steel, cosmic, darkmode</value>
1499+
</data>
1500+
<data name="ClearThemeResult" xml:space="preserve">
1501+
<value>清除个人资料主题 {0}</value>
1502+
</data>
1503+
<data name="SetThemeResult" xml:space="preserve">
1504+
<value>设置个人资料主题为 {0} {1}</value>
1505+
</data>
14971506
</root>

ASFEnhance/Profile/Command.cs

Lines changed: 134 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ internal static class Command
3333
sb.AppendLineFormat(Langs.ProfileNickname, result.NickName);
3434
sb.AppendLineFormat(Langs.ProfileState, result.IsOnline ? Langs.Online : Langs.Offline);
3535

36-
3736
sb.AppendLineFormat(Langs.ProfileLevel, result.Level);
3837

3938
if (result.BadgeCount > 0)
@@ -1083,4 +1082,138 @@ internal static class Command
10831082

10841083
return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null;
10851084
}
1085+
1086+
/// <summary>
1087+
/// 设置个人资料装饰器
1088+
/// </summary>
1089+
/// <param name="bot"></param>
1090+
/// <param name="strAppId"></param>
1091+
/// <param name="strItemId"></param>
1092+
/// <param name="enable"></param>
1093+
/// <returns></returns>
1094+
/// <exception cref="ArgumentNullException"></exception>
1095+
internal static async Task<string?> ResponseSetProfileModifier(Bot bot, string strAppId, string strItemId, bool enable)
1096+
{
1097+
if (!bot.IsConnectedAndLoggedOn)
1098+
{
1099+
return bot.FormatBotResponse(Strings.BotNotConnected);
1100+
}
1101+
1102+
if (!uint.TryParse(strAppId, out var appId))
1103+
{
1104+
return bot.FormatBotResponse(Langs.ArgumentNotInteger, nameof(appId));
1105+
}
1106+
1107+
if (!ulong.TryParse(strItemId, out var itemId))
1108+
{
1109+
return bot.FormatBotResponse(Langs.ArgumentNotInteger, nameof(itemId));
1110+
}
1111+
1112+
var result = await WebRequest.SetProfileModifier(bot, appId, itemId, enable).ConfigureAwait(false);
1113+
1114+
return bot.FormatBotResponse(result ? Langs.Success : Langs.Failure);
1115+
}
1116+
1117+
/// <summary>
1118+
/// 设置个人资料装饰器 (多个Bot)
1119+
/// </summary>
1120+
/// <param name="botNames"></param>
1121+
/// <param name="strAppId"></param>
1122+
/// <param name="strItemId"></param>
1123+
/// <param name="enable"></param>
1124+
/// <returns></returns>
1125+
/// <exception cref="ArgumentNullException"></exception>
1126+
internal static async Task<string?> ResponseSetProfileModifier(string botNames, string strAppId, string strItemId, bool enable)
1127+
{
1128+
if (string.IsNullOrEmpty(botNames))
1129+
{
1130+
throw new ArgumentNullException(nameof(botNames));
1131+
}
1132+
1133+
var bots = Bot.GetBots(botNames);
1134+
1135+
if (bots == null || bots.Count == 0)
1136+
{
1137+
return FormatStaticResponse(Strings.BotNotFound, botNames);
1138+
}
1139+
1140+
var results = await Utilities.InParallel(bots.Select(bot => ResponseSetProfileModifier(bot, strAppId, strItemId, enable))).ConfigureAwait(false);
1141+
var responses = new List<string?>(results.Where(result => !string.IsNullOrEmpty(result)));
1142+
1143+
return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null;
1144+
}
1145+
1146+
/// <summary>
1147+
/// 设置个人资料主题
1148+
/// </summary>
1149+
/// <param name="bot"></param>
1150+
/// <param name="themeName"></param>
1151+
/// <returns></returns>
1152+
/// <exception cref="ArgumentNullException"></exception>
1153+
internal static async Task<string?> ResponseSetProfileTheme(Bot bot, string? themeName)
1154+
{
1155+
if (!bot.IsConnectedAndLoggedOn)
1156+
{
1157+
return bot.FormatBotResponse(Strings.BotNotConnected);
1158+
}
1159+
1160+
if (!string.IsNullOrEmpty(themeName))
1161+
{
1162+
themeName = themeName.ToLowerInvariant();
1163+
1164+
List<string> choices = ["summer", "midnight", "steel", "cosmic", "darkmode"];
1165+
1166+
if (!choices.Contains(themeName))
1167+
{
1168+
if (themeName != "*")
1169+
{
1170+
return bot.FormatBotResponse(Langs.InvalidThemeName);
1171+
}
1172+
1173+
themeName = choices[Random.Shared.Next(choices.Count)];
1174+
}
1175+
}
1176+
else
1177+
{
1178+
themeName = null;
1179+
}
1180+
1181+
var result = await WebRequest.SetProfileTheme(bot, themeName).ConfigureAwait(false);
1182+
1183+
if (string.IsNullOrEmpty(themeName))
1184+
{
1185+
return bot.FormatBotResponse(Langs.ClearThemeResult, result ? Langs.Success : Langs.Failure);
1186+
}
1187+
else
1188+
{
1189+
return bot.FormatBotResponse(Langs.SetThemeResult, themeName, result ? Langs.Success : Langs.Failure);
1190+
}
1191+
}
1192+
1193+
/// <summary>
1194+
/// 设置个人资料主题 (多个Bot)
1195+
/// </summary>
1196+
/// <param name="botNames"></param>
1197+
/// <param name="themeName"></param>
1198+
/// <returns></returns>
1199+
/// <exception cref="ArgumentNullException"></exception>
1200+
internal static async Task<string?> ResponseSetProfileTheme(string botNames, string? themeName)
1201+
{
1202+
if (string.IsNullOrEmpty(botNames))
1203+
{
1204+
throw new ArgumentNullException(nameof(botNames));
1205+
}
1206+
1207+
var bots = Bot.GetBots(botNames);
1208+
1209+
if (bots == null || bots.Count == 0)
1210+
{
1211+
return FormatStaticResponse(Strings.BotNotFound, botNames);
1212+
}
1213+
1214+
var results = await Utilities.InParallel(bots.Select(bot => ResponseSetProfileTheme(bot, themeName))).ConfigureAwait(false);
1215+
var responses = new List<string?>(results.Where(result => !string.IsNullOrEmpty(result)));
1216+
1217+
return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null;
1218+
}
10861219
}

0 commit comments

Comments
 (0)