Skip to content

Commit

Permalink
新增APIKEYACCESSTOKEN命令
Browse files Browse the repository at this point in the history
修改`COOKIES`命令为可选特性
需要在ASF.json中设置`ASFEnhanceDevFuture=true`才会启用
  • Loading branch information
chr233 committed Feb 26, 2022
1 parent 41c3f5e commit 7b5d519
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 70 deletions.
18 changes: 18 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.

8 changes: 7 additions & 1 deletion ASFEnhance/Localization/Langs.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,12 @@
<value>No</value>
</data>
<data name="PurchaseFailed" xml:space="preserve">
<value>Purchase failed, wallet balence don't change.</value>
<value>Purchase failed, wallet balence don't change</value>
</data>
<data name="FetchDataFailed" xml:space="preserve">
<value>Fetch {0} failed</value>
</data>
<data name="DataIsNull" xml:space="preserve">
<value>{0} is NULL</value>
</data>
</root>
6 changes: 6 additions & 0 deletions ASFEnhance/Localization/Langs.resx
Original file line number Diff line number Diff line change
Expand Up @@ -303,4 +303,10 @@
<data name="PurchaseFailed" xml:space="preserve">
<value>购买失败, 余额未变动</value>
</data>
<data name="FetchDataFailed" xml:space="preserve">
<value>获取 {0} 失败</value>
</data>
<data name="DataIsNull" xml:space="preserve">
<value>{0} 是NULL</value>
</data>
</root>
6 changes: 6 additions & 0 deletions ASFEnhance/Localization/Langs.zh-CN.resx
Original file line number Diff line number Diff line change
Expand Up @@ -303,4 +303,10 @@
<data name="PurchaseFailed" xml:space="preserve">
<value>购买失败, 余额未变动</value>
</data>
<data name="FetchDataFailed" xml:space="preserve">
<value>获取 {0} 失败</value>
</data>
<data name="DataIsNull" xml:space="preserve">
<value>{0} 是NULL</value>
</data>
</root>
80 changes: 11 additions & 69 deletions ASFEnhance/Other/Command.cs
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
#pragma warning disable CS8632 // 只能在 "#nullable" 注释上下文内的代码中使用可为 null 的引用类型的注释。

using ArchiSteamFarm.Core;
using ArchiSteamFarm.Localization;
using ArchiSteamFarm.Steam;
using ArchiSteamFarm.Steam.Storage;
using Chrxw.ASFEnhance.Localization;
using SteamKit2;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static Chrxw.ASFEnhance.Utils;

namespace Chrxw.ASFEnhance.Other
{
internal static class Command
{
// 查看插件版本
/// <summary>
/// 查看插件版本
/// </summary>
/// <returns></returns>
internal static string ResponseASFEnhanceVersion()
{
Version version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;

return string.Format(CurrentCulture, Langs.PluginVer, version.Major, version.Minor, version.Build, version.Revision);
}
// 提取KEY

/// <summary>
/// 从文本提取Key
/// </summary>
/// <param name="message"></param>
/// <returns></returns>
internal static string? ResponseExtractKeys(string message)
{
List<string> keys = new();

MatchCollection matches;
matches = Regex.Matches(message, @"[\S\d]{5}-[\S\d]{5}-[\S\d]{5}", RegexOptions.IgnoreCase);
matches = Regex.Matches(message, @"[A-Z0-9]{5}-?[A-Z0-9]{5}-?[A-Z0-9]{5}", RegexOptions.IgnoreCase);
foreach (Match match in matches)
{
keys.Add(match.Value.ToUpperInvariant());
Expand All @@ -47,62 +46,5 @@ internal static string ResponseASFEnhanceVersion()

return keys.Count > 0 ? string.Join('\n', keys) : string.Format(CurrentCulture, Langs.KeyNotFound);
}
// 查看客户端Cookies
internal static string? ResponseGetCookies(Bot bot, ulong steamID)
{
if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount)
{
throw new ArgumentOutOfRangeException(nameof(steamID));
}

if (!bot.HasAccess(steamID, BotConfig.EAccess.Master))
{
return null;
}

if (!bot.IsConnectedAndLoggedOn)
{
return FormatBotResponse(bot, Strings.BotNotConnected);
}

StringBuilder response = new();

response.AppendLine(string.Format(CurrentCulture, Langs.ClientCookies));

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

foreach (Cookie c in cc)
{
response.AppendLine(string.Format(CurrentCulture, Langs.CookieItem, c.Name, c.Value));
}

return FormatBotResponse(bot, response.ToString());
}
// 查看客户端Cookies(多个bot)
internal static async Task<string?> ResponseGetCookies(ulong steamID, string botNames)
{
if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount)
{
throw new ArgumentOutOfRangeException(nameof(steamID));
}

if (string.IsNullOrEmpty(botNames))
{
throw new ArgumentNullException(nameof(botNames));
}

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

if ((bots == null) || (bots.Count == 0))
{
return ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(CurrentCulture, Strings.BotNotFound, botNames)) : null;
}

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

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

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

0 comments on commit 7b5d519

Please sign in to comment.