Skip to content

Commit

Permalink
修复Bug
Browse files Browse the repository at this point in the history
  • Loading branch information
chr233 committed Mar 2, 2022
1 parent 7aaad9c commit 1a435f2
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 216 deletions.
10 changes: 6 additions & 4 deletions ASFEnhance/ASFEnhance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

using Chrxw.ASFEnhance.Localization;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

using System;
Expand All @@ -23,7 +24,8 @@ internal sealed class ASFEnhance : IASF, IBotCommand2
public string Name => nameof(ASFEnhance);
public Version Version => typeof(ASFEnhance).Assembly.GetName().Version ?? throw new ArgumentNullException(nameof(Version));

private bool DeveloperFeature = false;
[JsonProperty]
public bool DeveloperFeature { get; private set; } = false;

/// <summary>
/// ASF启动事件
Expand All @@ -42,7 +44,7 @@ public Task OnASFInit(IReadOnlyDictionary<string, JToken>? additionalConfigPrope
switch (configProperty)
{
case "ASFEnhanceDevFuture" when configValue.Type == JTokenType.Boolean:
this.DeveloperFeature = configValue.Value<bool>();
DeveloperFeature = configValue.Value<bool>();
break;
}
}
Expand All @@ -57,10 +59,10 @@ public Task OnASFInit(IReadOnlyDictionary<string, JToken>? additionalConfigPrope
public Task OnLoaded()
{
Version version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
ASFLogger.LogGenericInfo(string.Format(CurrentCulture, Langs.PluginVer, version.Major, version.Minor, version.Build, version.Revision));
ASFLogger.LogGenericInfo(string.Format(CurrentCulture, Langs.PluginVer, nameof(ASFEnhance), version.Major, version.Minor, version.Build, version.Revision));
ASFLogger.LogGenericInfo(string.Format(CurrentCulture, Langs.PluginContact));

if (this.DeveloperFeature)
if (DeveloperFeature)
{
ASFLogger.LogGenericWarning(string.Format(CurrentCulture, Langs.DevFeatureEnabledWarning));
}
Expand Down
1 change: 0 additions & 1 deletion ASFEnhance/ASFEnhance.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
<PackageReference Include="ConfigureAwaitChecker.Analyzer" PrivateAssets="all" Version="5.0.0" />
<PackageReference Include="Newtonsoft.Json" IncludeAssets="compile" Version="13.0.1" />
<PackageReference Include="SteamKit2" IncludeAssets="compile" Version="2.4.1" />
<PackageReference Include="System.Composition.AttributedModel" IncludeAssets="compile" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions ASFEnhance/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System.Reflection;

[assembly: System.CLSCompliant(false)]
[assembly: AssemblyVersion("1.5.14.233")]
[assembly: AssemblyFileVersion("1.5.14.233")]
[assembly: AssemblyVersion("1.5.14.235")]
[assembly: AssemblyFileVersion("1.5.14.235")]

[assembly: AssemblyCopyright("Copyright © 2021 Chr_")]
[assembly: AssemblyCopyright("Copyright © 2022 Chr_")]
[assembly: AssemblyProduct("ASFEnhance")]
[assembly: AssemblyCompany("chrxw.com")]
[assembly: AssemblyTitle("An ArchiSteamFarm plugin developed by Chr_.")]
Expand Down
203 changes: 1 addition & 202 deletions ASFEnhance/Event/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using SteamKit2;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
using static Chrxw.ASFEnhance.Event.Response;
Expand All @@ -18,206 +17,6 @@ namespace Chrxw.ASFEnhance.Event
{
internal static class Command
{
// 冬促投票
internal static async Task<string?> ResponseSteamAwardVote(Bot bot, ulong steamID, string gameIDs)
{
if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount)
{
throw new InvalidEnumArgumentException(nameof(steamID));
}

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

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

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

List<uint> intGamsIDs = new();

foreach (string entry in entries)
{
if (uint.TryParse(entry, out uint choice))
{
intGamsIDs.Add(choice);
if (intGamsIDs.Count >= 10)
{
break;
}
}
}

if (intGamsIDs.Count < 10) //不足10个游戏自动补齐
{
Random rd = new();
uint[,] aviliableChoose = new uint[,] {
{ 892970 ,1063730 ,1091500 ,1196590 ,1551360 } ,
{ 752480 ,1358140 ,1402320 ,1499120 ,1576350 },
{ 570 ,105600 ,252490 ,275850 ,1172470 },
{ 892970 ,924970 ,1240440 ,1426210 ,1782210 },
{ 607080 ,848450 ,860510 ,1178830 ,1551360 },
{ 1092790 ,1097200 ,1195290 ,1252330 ,1282730 },
{ 699130 ,1203220 ,1325200 ,1466860 ,1517290 },
{ 1088850 ,1113560 ,1382330 ,1384160 ,1490890 },
{ 936790 ,1091500 ,1196590 ,1259420 ,1328670 },
{ 1135690 ,1210320 ,1248130 ,1291340 ,1455840 }
};
for (int i = intGamsIDs.Count; i < 10; i++)
{
intGamsIDs.Add(aviliableChoose[i, rd.Next(0, 5)]);
}
}

for (int i = 0; i < 10; i++)
{
int categoryID = 61 + i;
await WebRequest.MakeVote(bot, intGamsIDs[i], categoryID).ConfigureAwait(false);
}

uint? voteCount = await WebRequest.CheckSummerBadge(bot).ConfigureAwait(false);

if (voteCount == null)
{
return FormatBotResponse(bot, Langs.EventReadBadgeStatusFailed);
}

return FormatBotResponse(bot, string.Format(CurrentCulture, Langs.EventVoteResponse, voteCount, 10));
}

// 冬促投票(多个Bot)
internal static async Task<string?> ResponseSteamAwardVote(ulong steamID, string botNames, string choose)
{
if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount)
{
throw new InvalidEnumArgumentException(nameof(steamID));
}

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

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

if ((bots == null) || (bots.Count == 0))
{
// return access >= EAccess.Owner ? FormatStaticResponse(string.Format(CurrentCulture, Strings.BotNotFound, botNames)) : null;
}

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

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

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

// 检查冬促徽章
internal static async Task<string?> ResponseCheckSteamAwardVote(Bot bot, ulong steamID)
{
if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount)
{
throw new InvalidEnumArgumentException(nameof(steamID));
}

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

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

uint? voteCount = await WebRequest.CheckSummerBadge(bot).ConfigureAwait(false);

if (voteCount == null)
{
return FormatBotResponse(bot, Langs.EventReadBadgeStatusFailed);
}

return FormatBotResponse(bot, string.Format(CurrentCulture, Langs.EventVoteResponse, voteCount, 10));
}

// 冬促投票(多个Bot)
internal static async Task<string?> ResponseCheckSteamAwardVote(ulong steamID, string botNames)
{
if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount)
{
throw new InvalidEnumArgumentException(nameof(steamID));
}

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

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

if ((bots == null) || (bots.Count == 0))
{
// return access >= EAccess.Owner ? FormatStaticResponse(string.Format(CurrentCulture, Strings.BotNotFound, botNames)) : null;
}

IList<string?> results = await Utilities.InParallel(bots.Select(bot => ResponseCheckSteamAwardVote(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 async Task<string?> ResponseClaimDailySticker(Bot bot, ulong steamID)
{
if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount)
{
throw new InvalidEnumArgumentException(nameof(steamID));
}

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

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

bool? result = await WebRequest.ClaimDailySticker(bot).ConfigureAwait(false);

return FormatBotResponse(bot, string.Format(CurrentCulture, Langs.EventClaimItem, result));
}

// 领取每日贴纸(多个Bot)
internal static async Task<string?> ResponseClaimDailySticker(ulong steamID, string botNames)
{
if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount)
{
throw new InvalidEnumArgumentException(nameof(steamID));
}

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

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

if ((bots == null) || (bots.Count == 0))
{
// return access >= EAccess.Owner ? FormatStaticResponse(string.Format(CurrentCulture, Strings.BotNotFound, botNames)) : null;
}

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

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

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

}
}
2 changes: 1 addition & 1 deletion ASFEnhance/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Chrxw.ASFEnhance
{
internal class Utils
internal static class Utils
{
/// <summary>
/// 格式化返回文本
Expand Down
3 changes: 0 additions & 3 deletions ASFEnhance/WishList/WebRequest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma warning disable CS8632 // 只能在 "#nullable" 注释上下文内的代码中使用可为 null 的引用类型的注释。

using ArchiSteamFarm.Core;
using ArchiSteamFarm.Localization;
using ArchiSteamFarm.Steam;
using ArchiSteamFarm.Steam.Data;
Expand All @@ -24,7 +23,6 @@ internal static class WebRequest
/// <param name="bot"></param>
/// <param name="gameID"></param>
/// <returns></returns>
/// <exception cref="InvalidEnumArgumentException"></exception>
internal static async Task<bool> AddWishlist(Bot bot, uint gameID)
{
if (gameID == 0)
Expand Down Expand Up @@ -62,7 +60,6 @@ internal static async Task<bool> AddWishlist(Bot bot, uint gameID)
/// <param name="bot"></param>
/// <param name="gameID"></param>
/// <returns></returns>
/// <exception cref="InvalidEnumArgumentException"></exception>
internal static async Task<bool> RemoveWishlist(Bot bot, uint gameID)
{
if (gameID == 0)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Post link: [https://keylol.com/t716051-1-1](https://keylol.com/t716051-1-1)
| ASFEnhance Version | Compile Use ASF Version | Supported Lowest ASF Version | Note |
| -------------------------------------------------------------------------- | ----------------------- | ---------------------------- | ---------------------------------------------- |
| [1.5.14.233](https://github.com/chr233/ASFEnhance/releases/tag/1.5.14.233) | 5.2.2.5 | 5.2.2.5 | Plugin API changed, nolonger supported old ASF |
| [1.5.14.235](https://github.com/chr233/ASFEnhance/releases/tag/1.5.14.235) | 5.2.2.5 | 5.2.2.5 | Plugin API changed, nolonger supported old ASF |
| [1.5.13.231](https://github.com/chr233/ASFEnhance/releases/tag/1.5.13.231) | 5.1.2.5 | 5.1.2.5 | - |
| [1.5.12.230](https://github.com/chr233/ASFEnhance/releases/tag/1.5.12.230) | 5.1.2.5 | 5.1.2.5 | Migrate to .net6.0, nolonger supported old ASF |

Expand Down
2 changes: 1 addition & 1 deletion README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
| ASFEnhance 版本 | 编译依赖的 ASF 版本 | 最低支持的 ASF 版本 | 备注 |
| -------------------------------------------------------------------------- | ------------------- | ------------------- | -------------------------------- |
| [1.5.14.233](https://github.com/chr233/ASFEnhance/releases/tag/1.5.14.233) | 5.2.2.5 | 5.2.2.5 | 插件 API 更改, 无法兼容旧版 ASF |
| [1.5.14.235](https://github.com/chr233/ASFEnhance/releases/tag/1.5.14.235) | 5.2.2.5 | 5.2.2.5 | 插件 API 更改, 无法兼容旧版 ASF |
| [1.5.13.231](https://github.com/chr233/ASFEnhance/releases/tag/1.5.13.231) | 5.1.2.5 | 5.1.2.5 | - |
| [1.5.12.230](https://github.com/chr233/ASFEnhance/releases/tag/1.5.12.230) | 5.1.2.5 | 5.1.2.5 | 切换到 .net6.0, 无法兼容旧版 ASF |

Expand Down

0 comments on commit 1a435f2

Please sign in to comment.