Skip to content

Commit

Permalink
新增 COOKIES 命令
Browse files Browse the repository at this point in the history
修复 CART 命令价格识别错误的问题
完善文档
  • Loading branch information
chr233 committed Aug 22, 2021
1 parent c6509ca commit d1e93d6
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 43 deletions.
4 changes: 2 additions & 2 deletions ASFEnhance/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Reflection;

[assembly: AssemblyVersion("1.5.5.82")]
[assembly: AssemblyFileVersion("1.5.5.82")]
[assembly: AssemblyVersion("1.5.6.86")]
[assembly: AssemblyFileVersion("1.5.6.86")]
80 changes: 74 additions & 6 deletions ASFEnhance/Command.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
using ArchiSteamFarm.Core;
using ArchiSteamFarm.Localization;
using ArchiSteamFarm.Steam;
using ArchiSteamFarm.Steam.Integration;
using ArchiSteamFarm.Steam.Interaction;
using ArchiSteamFarm.Steam.Storage;
using SteamKit2;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using static Chrxw.ASFEnhance.Response;
Expand Down Expand Up @@ -36,11 +38,12 @@ internal class Command
case "CA":
return await ResponseGetCartGames(steamID, "ASF").ConfigureAwait(false);

case "ASFENHANCE":
case "ASFE":
return ResponseASFEnhanceVersion();

case "K":
case "KEY":
case "K":
return ResponseExtractKeys(Utilities.GetArgsAsText(message, 1));

case "CART":
Expand All @@ -67,6 +70,9 @@ internal class Command
case "PF":
return await ResponseGetProfileSummary(bot, steamID).ConfigureAwait(false);

case "COOKIES":
return ResponseGetCookies(bot, steamID);

default:
return null;
}
Expand Down Expand Up @@ -141,6 +147,9 @@ internal class Command
case "PF":
return await ResponseGetProfileSummary(steamID, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false);

case "COOKIES":
return await ResponseGetCookies(steamID, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false);

default:
return null;
}
Expand Down Expand Up @@ -173,7 +182,7 @@ private static string ResponseASFEnhanceVersion()
throw new ArgumentNullException(nameof(targetGameIDs));
}

if (!bot.HasAccess(steamID, BotConfig.EAccess.Operator))
if (!bot.HasAccess(steamID, BotConfig.EAccess.Master))
{
return null;
}
Expand Down Expand Up @@ -247,7 +256,7 @@ private static string ResponseASFEnhanceVersion()
throw new ArgumentNullException(nameof(targetGameIDs));
}

if (!bot.HasAccess(steamID, BotConfig.EAccess.Operator))
if (!bot.HasAccess(steamID, BotConfig.EAccess.Master))
{
return null;
}
Expand Down Expand Up @@ -490,7 +499,7 @@ private static string ResponseASFEnhanceVersion()
throw new ArgumentOutOfRangeException(nameof(steamID));
}

if (!bot.HasAccess(steamID, BotConfig.EAccess.Master))
if (!bot.HasAccess(steamID, BotConfig.EAccess.Operator))
{
return null;
}
Expand Down Expand Up @@ -807,8 +816,6 @@ private static string ResponseASFEnhanceVersion()
return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null;
}



// 获取购物车可用区域
private static async Task<string?> ResponseGetCartCountries(Bot bot, ulong steamID)
{
Expand Down Expand Up @@ -929,8 +936,69 @@ private static string ResponseASFEnhanceVersion()
return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null;
}


// 查看客户端Cookies
private 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(FormatBotResponse(bot, "Steam商店的Cookies:"));

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

foreach (Cookie c in cc)
{
response.AppendLine($"{c.Name} : {c.Value}");
}

return response.ToString();
}
// 查看客户端Cookies(多个bot)
async private static 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(CultureInfo.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;
}

internal static string FormatStaticResponse(string response) => Commands.FormatStaticResponse(response);
internal static string FormatBotResponse(Bot bot, string response) => bot.Commands.FormatBotResponse(response);
internal static Uri SteamStoreURL => ArchiWebHandler.SteamStoreURL;

}

}
2 changes: 1 addition & 1 deletion ASFEnhance/HtmlParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ internal class HtmlParser
Match match = Regex.Match(gameLink, @"\w+\/\d+");
string gamePath = match.Success ? match.Value : "出错";

match = Regex.Match(elePrice.TextContent, @"\d([,.]\d{1,3})*");
match = Regex.Match(elePrice.TextContent, @"[,.\d]+");
string strPrice = match.Success ? match.Value : "-1";

if (!dotMode)
Expand Down
64 changes: 30 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,54 +8,50 @@

### 实用功能

| 命令 | 说明 |
| ------------------- | ------------- |
| KEY | 从文本提取key |
| K | 同上 |
| PROFILE \[Bots\] | 查看个人资料 |
| PF \[Bots\] | 同上 |
| STEAMID \[Bots\] | 查看steamID |
| SID \[Bots\] | 同上 |
| FRIENDCODE \[Bots\] | 查看好友代码 |
| FC \[Bots\] | 同上 |
| 命令 | 缩写 | 权限 | 说明 |
| ------------------- | ------ | --------------- | ---------------------------------------------------------- |
| `KEY TEXT` | `K` | `Any` | 从文本提取key |
| `PROFILE [Bots]` | `PF` | `FamilySharing` | 查看个人资料 |
| `STEAMID [Bots]` | `SID` | `FamilySharing` | 查看steamID |
| `FRIENDCODE [Bots]` | `FC` | `FamilySharing` | 查看好友代码 |
| `COOKIES [Bots]` | - | `Master` | 查看Steam商店的Cookies(仅供调试使用,切勿泄露自己的Cookies) |
| `ASFENHANCE` | `ASFE` | `Any` | 查看ASFEnhance的版本 |

### 愿望单相关

| 命令 | 说明 |
| ----------------------------------- | ---------- |
| ADDWISHLIST \[Bots\] \<AppIDs\> | 添加愿望单 |
| AW \[Bots\] \<AppIDs\> | 同上 |
| REMOVEWISHLIST \[Bots\] \<AppIDs\> | 移除愿望单 |
| RW \[Bots\] \<AppIDs\> | 同上 |
| 命令 | 缩写 | 权限 | 说明 |
| -------------------------------- | ---- | -------- | ---------- |
| `ADDWISHLIST [Bots] <AppIDs>` | `AW` | `Master` | 添加愿望单 |
| `REMOVEWISHLIST [Bots] <AppIDs>` | `RW` | `Master` | 移除愿望单 |

### 商店相关

| 命令 | 说明 |
| ------------------------------------------- | ------------------------------ |
| SUBS \[Bots\] \<AppIDS\|SubIDS\|BundleIDS\> | 查询商店SUB,支持APP/SUB/BUNDLE |
| S \[Bots\] \<APPIDS\|SUBIDS\|BUNDLEIDS\> | 同上 |
| 命令 | 缩写 | 权限 | 说明 |
| --------------------------------------- | ---- | ---------- | ------------------------------ |
| `SUBS [Bots] <AppIDS|SubIDS|BundleIDS>` | `S` | `Operator` | 查询商店SUB,支持APP/SUB/BUNDLE |

### 购物车相关

> STEAM的购物车储存在Cookies里,重启ASF将会导致购物车清空
| 命令 | 说明 |
| ---------------------------- | ------------------------ |
| CART \[Bots\] | 查看机器人购物车 |
| C \[Bots\] | 同上 |
| ADDCART \[Bots\] \<SubIDs\> | 添加购物车,仅能使用SubID |
| AC \[Bots\] \<AppIDs\> | 同上 |
| CLEARCART \[Bots\] | 清空购物车 |
| CC \[Bots\] | 同上 |
| 命令 | 缩写 | 权限 | 说明 |
| ----------------------------------- | ---- | ---------- | ------------------------------------------------------------------------ |
| `CART [Bots]` | `C` | `Operator` | 查看机器人购物车 |
| `ADDCART [Bots] <SubIDs|BundleIDs>` | `AC` | `Operator` | 添加购物车,仅能使用`SubID``BundleID` |
| `CARTRESET [Bots]` | `CR` | `Operator` | 清空购物车 |
| `CARTCOUNTRY [Bots]` | `CC` | `Operator` | 获取购物车可用结算区域(跟账号钱包和当前IP所在地有关) |
| `SETCOUNTRY [Bots] CountryCode` | `SC` | `Operator` | 购物车改区,可以用`CARTCOUNTRY`命令获取当前可选的`CountryCode`(仍然有Bug) |

## ASF命令缩写

| 命令 | 说明 |
| ------------------------ | ------------------------------------------------ |
| AL \[Bots\] \<Licenses\> | 等同于`ADDLICENSE [Bots] <Licenses>`,添加免费SUB |
| LA | 等同于`LEVEL ASF`,获取所有机器人的等级 |
| BA | 等同于`BALANCE ASF`,获取所有机器人的钱包余额 |
| PA | 等同于`POINTS ASF`,获取所有机器人的点数余额 |
| 命令缩写 | 等价命令 | 说明 |
| ---------------------- | ------------------------------ | -------------------------- |
| `AL [Bots] <Licenses>` | `ADDLICENSE [Bots] <Licenses>` | 添加免费SUB |
| `LA` | `LEVEL ASF` | 获取所有机器人的等级 |
| `BA` | `BALANCE ASF` | 获取所有机器人的钱包余额 |
| `PA` | `POINTS ASF` | 获取所有机器人的点数余额 |
| `P [Bots]` | `POINTS` | 获取机器人的点数余额 |
| `CA` | `CART ASF` | 获取所有机器人的购物车信息 |

## 下载链接

Expand Down

0 comments on commit d1e93d6

Please sign in to comment.