Skip to content

Commit

Permalink
feat 新增 CHECKACCOUNTBANNED CHECKBOTBANNED 命令
Browse files Browse the repository at this point in the history
  • Loading branch information
chr233 committed Sep 12, 2023
1 parent 4c1ccd8 commit 88ae253
Show file tree
Hide file tree
Showing 8 changed files with 224 additions and 12 deletions.
15 changes: 15 additions & 0 deletions ASFEnhance/ASFEnhance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,11 @@ public Task OnLoaded()
case "NOO" when access >= EAccess.Operator:
return await Account.Command.ResponseGetNotificationOptions(bot).ConfigureAwait(false);

case "GETBOTBANNED" when access >= EAccess.Operator:
case "GETBOTBAN" when access >= EAccess.Operator:
case "GBB" when access >= EAccess.Operator:
return await Account.Command.ResponseGetAccountBanned(bot, null).ConfigureAwait(false);

//Cart
case "CART" when access >= EAccess.Operator:
case "C" when access >= EAccess.Operator:
Expand Down Expand Up @@ -492,6 +497,16 @@ public Task OnLoaded()
case "SNO" when access >= EAccess.Master:
return await Account.Command.ResponseSetNotificationOptions(bot, args[1]).ConfigureAwait(false);

case "GETBOTBANNED" when access >= EAccess.Operator:
case "GETBOTBAN" when access >= EAccess.Operator:
case "GBB" when access >= EAccess.Operator:
return await Account.Command.ResponseGetAccountBanned(Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false);

case "GETACCOUNTBANNED" when access >= EAccess.Operator:
case "GETACCOUNTBAN" when access >= EAccess.Operator:
case "GAB" when access >= EAccess.Operator:
return await Account.Command.ResponseSteamidAccountBanned(Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false);

//Cart
case "CART" when access >= EAccess.Operator:
case "C" when access >= EAccess.Operator:
Expand Down
152 changes: 151 additions & 1 deletion ASFEnhance/Account/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ private static string NotificationTargetToString(NotificationTarget target)

var bots = Bot.GetBots(botNames);

if ((bots == null) || (bots.Count == 0))
if (bots == null || bots.Count == 0)
{
return FormatStaticResponse(string.Format(Strings.BotNotFound, botNames));
}
Expand All @@ -711,4 +711,154 @@ private static string NotificationTargetToString(NotificationTarget target)

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

/// <summary>
/// 获取账户封禁情况
/// </summary>
/// <param name="bot"></param>
/// <param name="steamId"></param>
/// <returns></returns>
internal static async Task<string?> ResponseGetAccountBanned(Bot bot, ulong? steamId)
{
if (!bot.IsConnectedAndLoggedOn)
{
return bot.FormatBotResponse(Strings.BotNotConnected);
}

(_, string? apiKey) = await bot.ArchiWebHandler.CachedApiKey.GetValue().ConfigureAwait(false);

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

var result = await WebRequest.GetPlayerBans(bot, apiKey, steamId ?? bot.SteamID).ConfigureAwait(false);

if (result == null)
{
return bot.FormatBotResponse(Langs.NetworkError);
}

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

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)));
if (player.VACBanned)
{
sb.AppendLine(string.Format(" {0} bans, {1} days since last ban", player.NumberOfVACBans, player.DaysSinceLastBan));
}
else
{
sb.AppendLine();
}
var gameban = player.NumberOfGameBans > 0;
sb.Append(string.Format("游戏封禁: {0}", Bool2Str(gameban)));
if (gameban)
{
sb.AppendLine(string.Format(" {0} bans", player.NumberOfGameBans));
}
else
{
sb.AppendLine();
}

return sb.ToString();
}

/// <summary>
/// 获取账户封禁情况 (多个Bot)
/// </summary>
/// <param name="botNames"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
internal static async Task<string?> ResponseGetAccountBanned(string botNames)
{
if (string.IsNullOrEmpty(botNames))
{
throw new ArgumentNullException(nameof(botNames));
}

var targetBots = Bot.GetBots(botNames);

if (targetBots?.Any() != true)
{
return FormatStaticResponse(string.Format(Strings.BotNotFound, botNames));
}

var results = await Utilities.InParallel(targetBots.Select(bot => ResponseGetAccountBanned(bot, null))).ConfigureAwait(false);

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

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

/// <summary>
/// 获取账户封禁情况 (多个Bot)
/// </summary>
/// <param name="steamIds"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
internal static async Task<string?> ResponseSteamidAccountBanned(string query)
{
if (string.IsNullOrEmpty(query))
{
throw new ArgumentNullException(nameof(query));
}

Bot? bot = null;
var bs = Bot.GetBots("ASF");
if (bs?.Any() == true)
{
foreach (var b in bs)
{
if (b.IsConnectedAndLoggedOn)
{
bot = b;
break;
}
}
}

if (bot == null)
{
return FormatStaticResponse(string.Format(Strings.NoBotsAreRunning));
}

var steamIds = new List<ulong>();

string[] entries = query.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

foreach (string entry in entries)
{
if (ulong.TryParse(entry, out ulong value))
{
if (value < 0x110000100000000)
{
value += 0x110000100000000;
}
steamIds.Add(value);
}
}

if (steamIds?.Any() != true)
{
return FormatStaticResponse(string.Format(Strings.BotNotFound, steamIds));
}

var results = await Utilities.InParallel(steamIds.Select(x => ResponseGetAccountBanned(bot, x))).ConfigureAwait(false);

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

return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null;
}
}
17 changes: 17 additions & 0 deletions ASFEnhance/Account/WebRequest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using ArchiSteamFarm.Core;
using ArchiSteamFarm.Steam;
using ArchiSteamFarm.Steam.Data;
using ArchiSteamFarm.Steam.Integration;
using ArchiSteamFarm.Web.Responses;
using ASFEnhance.Data;
using Newtonsoft.Json;
Expand Down Expand Up @@ -309,4 +310,20 @@ internal static async Task<bool> RemoveLicense(Bot bot, uint subId)
var response = await bot.ArchiWebHandler.UrlPostToJsonObjectWithSession<ResultResponse>(request, referer: SteamStoreURL, data: data).ConfigureAwait(false);
return response?.Content;
}

/// <summary>
/// 获取用户封禁状态
/// </summary>
/// <param name="bot"></param>
/// <param name="token"></param>
/// <param name="steamids"></param>
/// <returns></returns>
internal static async Task<GetPlayerBansResponse?> GetPlayerBans(Bot bot, string token, ulong steamids)
{
Uri request = new(SteamApiURL, $"/ISteamUser/GetPlayerBans/v1/?key={token}&steamids={steamids}");

var response = await bot.ArchiWebHandler.UrlGetToJsonObjectWithSession<GetPlayerBansResponse>(request, referer: SteamStoreURL).ConfigureAwait(false);

return response?.Content;
}
}
4 changes: 2 additions & 2 deletions ASFEnhance/Cart/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ internal static class Command
response.AppendLine(string.Format(Langs.CartItemInfo, cartItem.GameId, cartItem.Name, cartItem.Price / 100.0));
}

response.AppendLine(string.Format(Langs.CartPurchaseSelf, cartResponse.PurchaseForSelf ? "" : "×"));
response.AppendLine(string.Format(Langs.CartPurchaseGift, cartResponse.PurchaseAsGift ? "" : "×"));
response.AppendLine(string.Format(Langs.CartPurchaseSelf, Bool2Str(cartResponse.PurchaseForSelf)));
response.AppendLine(string.Format(Langs.CartPurchaseGift, Bool2Str(cartResponse.PurchaseAsGift)));
}
else
{
Expand Down
23 changes: 23 additions & 0 deletions ASFEnhance/Data/GetPlayerBansResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Newtonsoft.Json;

namespace ASFEnhance.Data;
/// <summary>
/// 获取封禁状态
/// </summary>
internal sealed record GetPlayerBansResponse
{
[JsonProperty("players")]
public List<PlayerData>? Players { get; set; }

public sealed record PlayerData
{
public ulong SteamId { get; set; }
public bool CommunityBanned { get; set; }
public bool VACBanned { get; set; }
public int NumberOfVACBans { get; set; }
public int DaysSinceLastBan { get; set; }
public int NumberOfGameBans { get; set; }
public string EconomyBan { get; set; } = "none";
}
}

16 changes: 8 additions & 8 deletions ASFEnhance/DevFeature/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ internal static class Command
return bot.FormatBotResponse(Strings.BotNotConnected);
}

StringBuilder response = new();
var response = new StringBuilder();

response.AppendLine(Langs.MultipleLineResult);
response.AppendLine(Langs.ClientCookies);

CookieCollection cc = bot.ArchiWebHandler.WebBrowser.CookieContainer.GetCookies(SteamStoreURL);
var cc = bot.ArchiWebHandler.WebBrowser.CookieContainer.GetCookies(SteamStoreURL);

foreach (var c in cc.ToList())
{
Expand All @@ -48,14 +48,14 @@ 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))
{
return FormatStaticResponse(string.Format(Strings.BotNotFound, botNames));
}

IList<string?> results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => ResponseGetCookies(bot)))).ConfigureAwait(false);
var results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => ResponseGetCookies(bot)))).ConfigureAwait(false);

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

Expand Down Expand Up @@ -95,14 +95,14 @@ 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))
{
return FormatStaticResponse(string.Format(Strings.BotNotFound, botNames));
}

IList<string?> results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => ResponseGetAPIKey(bot)))).ConfigureAwait(false);
var results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => ResponseGetAPIKey(bot)))).ConfigureAwait(false);

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

Expand Down Expand Up @@ -142,14 +142,14 @@ 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))
{
return FormatStaticResponse(string.Format(Strings.BotNotFound, botNames));
}

IList<string?> results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => ResponseGetAccessToken(bot)))).ConfigureAwait(false);
var results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => ResponseGetAccessToken(bot)))).ConfigureAwait(false);

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

Expand Down
7 changes: 7 additions & 0 deletions ASFEnhance/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,11 @@ internal static void BypassAgeCheck(this ArchiWebHandler webHandler)
/// 日志
/// </summary>
internal static ArchiLogger ASFLogger => ASF.ArchiLogger;

/// <summary>
/// 布尔转换为char
/// </summary>
/// <param name="b"></param>
/// <returns></returns>
internal static char Bool2Str(bool b) => b ? '√' : '×';
}
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>1.8.9.0</Version>
<Version>1.8.10.0</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down

0 comments on commit 88ae253

Please sign in to comment.