Skip to content

Commit

Permalink
feat 新增 CLAIM20TH 命令
Browse files Browse the repository at this point in the history
  • Loading branch information
chr233 committed Sep 14, 2023
1 parent 2c96654 commit fce12a9
Show file tree
Hide file tree
Showing 10 changed files with 292 additions and 24 deletions.
8 changes: 8 additions & 0 deletions ASFEnhance/ASFEnhance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ public Task OnLoaded()
case "CI" when access >= EAccess.Operator:
return await Event.Command.ResponseClaimItem(bot).ConfigureAwait(false);

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

//Shortcut
case "P":
return await bot.Commands.Response(access, "POINTS", steamId).ConfigureAwait(false);
Expand Down Expand Up @@ -431,6 +435,10 @@ public Task OnLoaded()
case "CI" when access >= EAccess.Operator:
return await Event.Command.ResponseClaimItem(Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false);

case "CLAIM20TH" when access >= EAccess.Operator:
case "C20" when access >= EAccess.Operator:
return await Event.Command.ResponseClaim20Th(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
18 changes: 9 additions & 9 deletions ASFEnhance/Account/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ private static string NotificationTargetToString(NotificationTarget target)

if (string.IsNullOrEmpty(apiKey))
{
return bot.FormatBotResponse("网络错误");
return bot.FormatBotResponse(Langs.NetworkError);
}

var result = await WebRequest.GetPlayerBans(bot, apiKey, steamId ?? bot.SteamID).ConfigureAwait(false);
Expand All @@ -741,31 +741,31 @@ private static string NotificationTargetToString(NotificationTarget target)

if (result.Players?.Any() != true)
{
return bot.FormatBotResponse("未查询到封禁信息");
return bot.FormatBotResponse(Langs.NoUserFound);
}

var sb = new StringBuilder();
sb.AppendLine(bot.FormatBotResponse(Langs.MultipleLineResult));

var player = result.Players.First();

sb.AppendLine(string.Format("SteamId: {0}", player.SteamId));
sb.AppendLine(string.Format("社区封禁: {0}", Bool2Str(player.CommunityBanned)));
sb.AppendLine(string.Format("市场封禁: {0}", player.EconomyBan == "none" ? "×" : player.EconomyBan));
sb.Append(string.Format("VAC封禁: {0}", Bool2Str(player.VACBanned)));
sb.AppendLine(string.Format(Langs.BanSteamId, player.SteamId));
sb.AppendLine(string.Format(Langs.BanCommunity, Bool2Str(player.CommunityBanned)));
sb.AppendLine(string.Format(Langs.BanEconomy, player.EconomyBan == "none" ? "×" : player.EconomyBan));
sb.Append(string.Format(Langs.BanVAC, Bool2Str(player.VACBanned)));
if (player.VACBanned)
{
sb.AppendLine(string.Format(" {0} bans, {1} days since last ban", player.NumberOfVACBans, player.DaysSinceLastBan));
sb.AppendLine(string.Format(Langs.BanVACCount, player.NumberOfVACBans, player.DaysSinceLastBan));
}
else
{
sb.AppendLine();
}
var gameban = player.NumberOfGameBans > 0;
sb.Append(string.Format("游戏封禁: {0}", Bool2Str(gameban)));
sb.Append(string.Format(Langs.BanGame, Bool2Str(gameban)));
if (gameban)
{
sb.AppendLine(string.Format(" {0} bans", player.NumberOfGameBans));
sb.AppendLine(string.Format(Langs.BanGameCount, player.NumberOfGameBans));
}
else
{
Expand Down
62 changes: 55 additions & 7 deletions ASFEnhance/Event/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ internal static class Command
throw new ArgumentNullException(nameof(botNames));
}

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

if ((bots == null) || (bots.Count == 0))
{
Expand Down Expand Up @@ -102,7 +102,7 @@ internal static class Command
throw new ArgumentNullException(nameof(botNames));
}

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

if ((bots == null) || (bots.Count == 0))
{
Expand Down Expand Up @@ -170,7 +170,7 @@ internal static class Command
throw new ArgumentNullException(nameof(botNames));
}

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

if ((bots == null) || (bots.Count == 0))
{
Expand Down Expand Up @@ -239,7 +239,7 @@ internal static class Command
throw new ArgumentNullException(nameof(botNames));
}

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

if ((bots == null) || (bots.Count == 0))
{
Expand Down Expand Up @@ -272,8 +272,6 @@ internal static class Command
return bot.FormatBotResponse(Langs.NetworkError);
}

ASFLogger.LogGenericInfo(token);

await WebRequest.ClaimDailySticker(bot, token).ConfigureAwait(false);

return bot.FormatBotResponse(Langs.Done);
Expand All @@ -292,7 +290,7 @@ internal static class Command
throw new ArgumentNullException(nameof(botNames));
}

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

if ((bots == null) || (bots.Count == 0))
{
Expand All @@ -305,4 +303,54 @@ internal static class Command

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


internal static async Task<string?> ResponseClaim20Th(Bot bot)
{
if (!bot.IsConnectedAndLoggedOn)
{
return bot.FormatBotResponse(Strings.BotNotConnected);
}

var (_, token) = await bot.ArchiWebHandler.CachedAccessToken.GetValue().ConfigureAwait(false);

if (string.IsNullOrEmpty(token))
{
return bot.FormatBotResponse(Langs.NetworkError);
}

var defIds = new List<int> { 241812, 241811, 241810, 241809, 241807, 241808 };

var results = await Utilities.InParallel(defIds.Select(id => WebRequest.RedeenPointShopItem(bot, token, id))).ConfigureAwait(false);

var count = 0;
foreach (var result in results)
{
if (result) count++;
}

return bot.FormatBotResponse(string.Format(Langs.SendRequestSuccess, count));
}


internal static async Task<string?> ResponseClaim20Th(string botNames)
{
if (string.IsNullOrEmpty(botNames))
{
throw new ArgumentNullException(nameof(botNames));
}

var 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 => ResponseClaim20Th(bot))).ConfigureAwait(false);

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

return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null;
}
}
34 changes: 27 additions & 7 deletions ASFEnhance/Event/WebRequest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using AngleSharp.Dom;
using ArchiSteamFarm.Steam;
using ArchiSteamFarm.Steam.Integration;
using static System.Runtime.InteropServices.JavaScript.JSType;

namespace ASFEnhance.Event;

Expand All @@ -15,9 +16,9 @@ internal static class WebRequest
/// <returns></returns>
internal static async Task DoEventTask(Bot bot, string clan_accountid, uint door_index)
{
Uri request = new(SteamStoreURL, "/saleaction/ajaxopendoor");
var request = new Uri(SteamStoreURL, "/saleaction/ajaxopendoor");

Dictionary<string, string> data = new(3) {
var data = new Dictionary<string, string>(3) {
{"door_index", door_index.ToString()},
{"clan_accountid", clan_accountid},
};
Expand All @@ -33,7 +34,7 @@ internal static async Task DoEventTask(Bot bot, string clan_accountid, uint door
/// <returns></returns>
internal static async Task<string?> FetchEventToken(Bot bot, string salePage)
{
Uri request = new(SteamStoreURL, $"/sale/{salePage}");
var request = new Uri(SteamStoreURL, $"/sale/{salePage}");

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

Expand All @@ -58,7 +59,7 @@ internal static async Task DoEventTask(Bot bot, string clan_accountid, uint door
/// <returns></returns>
internal static async Task<string?> FetchEventToken(Bot bot, string developer, string salePage)
{
Uri request = new(SteamStoreURL, $"/developer/{developer}/sale/{salePage}");
var request = new Uri(SteamStoreURL, $"/developer/{developer}/sale/{salePage}");

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

Expand All @@ -81,7 +82,7 @@ internal static async Task DoEventTask(Bot bot, string clan_accountid, uint door
/// <returns></returns>
internal static async Task<string?> FetchToken(Bot bot)
{
Uri request = new(SteamStoreURL, "/category/sports");
var request = new Uri(SteamStoreURL, "/category/sports");

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

Expand All @@ -105,11 +106,30 @@ internal static async Task DoEventTask(Bot bot, string clan_accountid, uint door
/// <returns></returns>
internal static async Task<bool> ClaimDailySticker(Bot bot, string token)
{
Uri request = new($"https://api.steampowered.com/ISaleItemRewardsService/ClaimItem/v1?access_token={token}");
Uri referer = new(SteamStoreURL, "/sale/16212626125");
var request = new Uri(SteamApiURL, $"/ISaleItemRewardsService/ClaimItem/v1?access_token={token}");
var referer = new Uri(SteamStoreURL, "/sale/16212626125");

await bot.ArchiWebHandler.UrlPostWithSession(request, referer: referer, session: ArchiWebHandler.ESession.None).ConfigureAwait(false);

return true;
}

/// <summary>
/// 领取点数商店物品
/// </summary>
/// <param name="bot"></param>
/// <param name="token"></param>
/// <returns></returns>
internal static async Task<bool> RedeenPointShopItem(Bot bot, string token, int defId)
{
var request = new Uri(SteamApiURL, $"/ILoyaltyRewardsService/RedeemPoints/v1?access_token={token}");

var data = new Dictionary<string, string>(1) {
{"defId", defId.ToString()},
};

var result = await bot.ArchiWebHandler.UrlPostWithSession(request, referer: SteamStoreURL, data: data, session: ArchiWebHandler.ESession.None).ConfigureAwait(false);

return result;
}
}
81 changes: 81 additions & 0 deletions ASFEnhance/Localization/Langs.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions ASFEnhance/Localization/Langs.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1047,4 +1047,31 @@
<data name="NtMobile" xml:space="preserve">
<value>, Push notification in the Mobile App</value>
</data>
<data name="BanSteamId" xml:space="preserve">
<value>SteamId: {0}</value>
</data>
<data name="BanVACCount" xml:space="preserve">
<value> {0} bans, last banned since {1} days</value>
</data>
<data name="BanVAC" xml:space="preserve">
<value>VAC banned: {0}</value>
</data>
<data name="BanGameCount" xml:space="preserve">
<value> {0} bans</value>
</data>
<data name="BanGame" xml:space="preserve">
<value>Game banned: {0}</value>
</data>
<data name="BanEconomy" xml:space="preserve">
<value>Economy banned: {0}</value>
</data>
<data name="BanCommunity" xml:space="preserve">
<value>Community banned: {0}</value>
</data>
<data name="NoUserFound" xml:space="preserve">
<value>No user data found</value>
</data>
<data name="SendRequestSuccess" xml:space="preserve">
<value>Send {0} requests successful</value>
</data>
</root>
Loading

0 comments on commit fce12a9

Please sign in to comment.