Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
chr233 committed May 30, 2023
1 parent 3bada87 commit a388f58
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 22 deletions.
19 changes: 14 additions & 5 deletions ASFBuffBot/Core/Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,21 @@ internal static async Task<bool> CheckDeliver(Bot bot)
}
else
{
Utils.Logger.LogGenericWarning(string.Format(Langs.TradeDismatchAutoReject, tradeId));
if (Utils.Config.RejectNotMatch)
{
Utils.Logger.LogGenericWarning(string.Format(Langs.TradeDismatchAutoReject, tradeId));

var result = await WebRequest.DeclineTradeOffer(bot, tradeId).ConfigureAwait(false);
Utils.Logger.LogGenericWarning(string.Format(Langs.RejectTrade, result ? Langs.Success : Langs.Failure, tradeId));
BotTradeCache.TryRemove(tradeId, out _);
status.DeliverRejectCount++;
}
else
{
Utils.Logger.LogGenericWarning(string.Format(Langs.TradeDismatch, tradeId));

}

var result = await WebRequest.DeclineTradeOffer(bot, tradeId).ConfigureAwait(false);
Utils.Logger.LogGenericWarning(string.Format(Langs.RejectTrade, result ? Langs.Success : Langs.Failure, tradeId));
BotTradeCache.TryRemove(tradeId, out _);
status.DeliverRejectCount++;
continue;
}
}
Expand Down
8 changes: 5 additions & 3 deletions ASFBuffBot/Core/WebRequest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using ArchiSteamFarm.Steam;
using ArchiSteamFarm.Steam.Integration;
using ArchiSteamFarm.Web;
using ArchiSteamFarm.Web.Responses;
using ASFBuffBot.Data;

Expand Down Expand Up @@ -40,7 +42,7 @@ internal static async Task<bool> CheckCookiesValid(Bot bot)
{
var request = new Uri(Utils.BuffUrl, "/api/message/notification");
var headers = GenerateBuffHeader();
var response = await bot.ArchiWebHandler.UrlGetToJsonObjectWithSession<BuffNotificationResponse>(request, headers, requestOptions: ArchiSteamFarm.Web.WebBrowser.ERequestOptions.ReturnRedirections, checkSessionPreemptively: false, allowSessionRefresh: false).ConfigureAwait(false);
var response = await bot.ArchiWebHandler.UrlGetToJsonObjectWithSession<BuffNotificationResponse>(request, headers, requestOptions: WebBrowser.ERequestOptions.ReturnRedirections, checkSessionPreemptively: false, allowSessionRefresh: false).ConfigureAwait(false);
return response?.Content;
}

Expand All @@ -53,7 +55,7 @@ internal static async Task<bool> CheckCookiesValid(Bot bot)
{
var request = new Uri(Utils.BuffUrl, "/api/market/steam_trade");
var headers = GenerateBuffHeader();
var response = await bot.ArchiWebHandler.UrlGetToJsonObjectWithSession<BuffSteamTradeResponse>(request, headers, requestOptions: ArchiSteamFarm.Web.WebBrowser.ERequestOptions.ReturnRedirections, checkSessionPreemptively: false, allowSessionRefresh: false).ConfigureAwait(false);
var response = await bot.ArchiWebHandler.UrlGetToJsonObjectWithSession<BuffSteamTradeResponse>(request, headers, requestOptions: WebBrowser.ERequestOptions.ReturnRedirections, checkSessionPreemptively: false, allowSessionRefresh: false).ConfigureAwait(false);
return response?.Content;
}

Expand All @@ -67,7 +69,7 @@ internal static async Task<bool> CheckCookiesValid(Bot bot)
{
var request = new Uri(Utils.BuffUrl, "/account/api/user/info");
var headers = GenerateBuffHeader();
var response = await bot.ArchiWebHandler.UrlGetToJsonObjectWithSession<BuffUserInfoResponse>(request, headers, requestOptions: ArchiSteamFarm.Web.WebBrowser.ERequestOptions.ReturnRedirections, checkSessionPreemptively: false, allowSessionRefresh: false).ConfigureAwait(false);
var response = await bot.ArchiWebHandler.UrlGetToJsonObjectWithSession<BuffUserInfoResponse>(request, headers, requestOptions: WebBrowser.ERequestOptions.ReturnRedirections, checkSessionPreemptively: false, allowSessionRefresh: false).ConfigureAwait(false);
return response?.Content;
}

Expand Down
6 changes: 6 additions & 0 deletions ASFBuffBot/Data/PluginConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,10 @@ public sealed record PluginConfig
/// </summary>
[JsonProperty(Required = Required.Default)]
public string? CustomUserAgent { get; set; }

/// <summary>
/// 交易不匹配时自动拒绝
/// </summary>
[JsonProperty(Required = Required.Default)]
public bool RejectNotMatch { get; set; }
}
9 changes: 9 additions & 0 deletions ASFBuffBot/Localization/Langs.Designer.cs

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

3 changes: 3 additions & 0 deletions ASFBuffBot/Localization/Langs.resx
Original file line number Diff line number Diff line change
Expand Up @@ -432,4 +432,7 @@
<data name="EnabledButOffline" xml:space="preserve">
<value>已启用自动发货, 但是当前机器人离线</value>
</data>
<data name="TradeDismatch" xml:space="preserve">
<value>交易物品不匹配, Id: {0}</value>
</data>
</root>
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.0.7.0</Version>
<Version>1.0.8.0</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down
31 changes: 18 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# ASFBuffBot

[![Codacy Badge](https://app.codacy.com/project/badge/Grade/28d15406751f42f499e2f53fde5bb808)](https://www.codacy.com/gh/chr233/ASFBuffBot/dashboard)
![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/chr233/ASFBuffBot/autobuild.yml?logo=github)
[![License](https://img.shields.io/github/license/chr233/ASFBuffBot?logo=apache)](https://github.com/chr233/ASFBuffBot/blob/master/license)
Expand Down Expand Up @@ -38,6 +39,7 @@ ASFBuffBot 介绍 & 使用指南: [https://keylol.com/t887696-1-1](https://keylo

| ASFBuffBot 版本 | 适配 ASF 版本 | 更新说明 |
| -------------------------------------------------------------------- | :-----------: | ------------------------------------------------------ |
| [1.0.8.0](https://github.com/chr233/ASFBuffBot/releases/tag/1.0.8.0) | 5.4.5.2 | 新增 `RejectNotMatch` 选项 |
| [1.0.7.0](https://github.com/chr233/ASFBuffBot/releases/tag/1.0.7.0) | 5.4.5.2 | 增加命令 `UPDATECOOKIESBOT` 用于手动设置机器人 cookies |
| [1.0.6.0](https://github.com/chr233/ASFBuffBot/releases/tag/1.0.6.0) | 5.4.5.2 | bug 修复 |
| [1.0.5.0](https://github.com/chr233/ASFBuffBot/releases/tag/1.0.5.0) | 5.4.5.2 | 支持自动登录 Buff, bug 修复 |
Expand All @@ -62,18 +64,20 @@ ASF.json
"DisabledCmds": ["foo", "bar"],
"BuffCheckInterval": 180,
"BotInterval": 30,
"CustomUserAgent": null
"CustomUserAgent": null,
"RejectNotMatch": false
}
}
```

| 配置项 | 类型 | 默认值 | 说明 |
| ------------------- | ------ | ------ | --------------------------------------------------------------------------------- |
| `Statistic` | bool | `true` | 是否允许发送统计数据, 仅用于统计插件用户数量, 不会发送任何其他信息 |
| `DisabledCmds` | list | `null` | 在此列表中的命令将会被禁用\*\* , **不区分大小写**, 仅对 `ASFBuffBot` 中的命令生效 |
| `BuffCheckInterval` | int | `180` | 每一轮 Buff 发货检查的周期, 单位秒, 访问频率过快容易被 ban |
| `BotInterval` | int | `30` | 在一轮发货检查中每个机器人的检查间隔, 单位秒 |
| `CustomUserAgent` | string | `null` | 自定义 `User-Agent` 用于向 Buff 发送请求 |
| 配置项 | 类型 | 默认值 | 说明 |
| ------------------- | ------ | ------- | --------------------------------------------------------------------------------- |
| `Statistic` | bool | `true` | 是否允许发送统计数据, 仅用于统计插件用户数量, 不会发送任何其他信息 |
| `DisabledCmds` | list | `null` | 在此列表中的命令将会被禁用\*\* , **不区分大小写**, 仅对 `ASFBuffBot` 中的命令生效 |
| `BuffCheckInterval` | int | `180` | 每一轮 Buff 发货检查的周期, 单位秒, 访问频率过快容易被 ban |
| `BotInterval` | int | `30` | 在一轮发货检查中每个机器人的检查间隔, 单位秒 |
| `CustomUserAgent` | string | `null` | 自定义 `User-Agent` 用于向 Buff 发送请求 |
| `RejectNotMatch` | bool | `false` | 交易物品不匹配时是否自动拒绝交易 |

> \*\* `DisabledCmds` 配置说明: 该项配置**不区分大小写**, 仅对 `ASFBuffBot` 中的命令有效
> 例如配置为 `["foo","BAR"]` , 则代表 `FOO``BAR` 命令将会被禁用
Expand All @@ -92,8 +96,9 @@ ASF.json

### 功能指令

| 命令 | 缩写 | 权限 | 说明 |
| -------------------- | ---- | -------- | ------------------------------------------------------------- |
| `ENABLEBUFF [Bots]` | `EB` | `Master` | 为指定机器人开启自动发货功能, 将会尝试自动登录到 buff.163.com |
| `DISABLEBUFF [Bots]` | `DB` | `Master` | 为指定机器人开启自动发货功能 |
| `BUFFSTATUS [Bots]` | `BS` | `Master` | 查看指定机器人自动发货状态 |
| 命令 | 缩写 | 权限 | 说明 |
| ------------------------------ | ----- | -------- | ------------------------------------------------------------- |
| `ENABLEBUFF [Bots]` | `EB` | `Master` | 为指定机器人开启自动发货功能, 将会尝试自动登录到 buff.163.com |
| `DISABLEBUFF [Bots]` | `DB` | `Master` | 为指定机器人开启自动发货功能 |
| `BUFFSTATUS [Bots]` | `BS` | `Master` | 查看指定机器人自动发货状态 |
| `UPDATECOOKIESBOT Bot Cookies` | `UCB` | `Master` | 查看指定机器人自动发货状态 |

0 comments on commit a388f58

Please sign in to comment.