diff --git a/ASFEnhance/ASFEnhance.cs b/ASFEnhance/ASFEnhance.cs index efb4b4b9..f9230e69 100644 --- a/ASFEnhance/ASFEnhance.cs +++ b/ASFEnhance/ASFEnhance.cs @@ -285,11 +285,6 @@ public Task OnLoaded() "L" when access >= EAccess.Operator => Account.Command.ResponseGetAccountLicenses(bot, false), - "REMOVEDEMOS" or - "REMOVEDEMO" or - "RD" when access >= EAccess.Master => - Account.Command.ResponseRemoveAllDemos(bot), - "EMAILOPTIONS" or "EMAILOPTION" or "EO" when access >= EAccess.Operator => @@ -524,21 +519,6 @@ public Task OnLoaded() "L" when access >= EAccess.Operator => Account.Command.ResponseGetAccountLicenses(Utilities.GetArgsAsText(args, 1, ","), false), - "REMOVEDEMOS" or - "REMOVEDEMO" or - "RD" when access >= EAccess.Master => - Account.Command.ResponseRemoveAllDemos(Utilities.GetArgsAsText(args, 1, ",")), - - "REMOVELICENSES" or - "REMOVELICENSE" or - "RL" when argLength > 2 && access >= EAccess.Master => - Account.Command.ResponseRemoveFreeLicenses(args[1], Utilities.GetArgsAsText(args, 2, ",")), - - "REMOVELICENSES" or - "REMOVELICENSE" or - "RL" when access >= EAccess.Master => - Account.Command.ResponseRemoveFreeLicenses(bot, args[1]), - "EMAILOPTIONS" or "EMAILOPTION" or "EO" when access >= EAccess.Operator => diff --git a/ASFEnhance/Account/Command.cs b/ASFEnhance/Account/Command.cs index 0044ab10..46e22cea 100644 --- a/ASFEnhance/Account/Command.cs +++ b/ASFEnhance/Account/Command.cs @@ -133,231 +133,6 @@ internal static class Command return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } - /// - /// 移除免费许可证 - /// - /// - /// - /// - internal static async Task ResponseRemoveFreeLicenses(Bot bot, string query) - { - if (!bot.IsConnectedAndLoggedOn) - { - return bot.FormatBotResponse(Strings.BotNotConnected); - } - - if (string.IsNullOrEmpty(query)) - { - return bot.FormatBotResponse(Langs.ArgsIsEmpty); - } - - var licensesOld = await WebRequest.GetOwnedLicenses(bot).ConfigureAwait(false); - - if (licensesOld == null) - { - return bot.FormatBotResponse(Langs.NetworkError); - } - - var oldSubs = licensesOld.Where(x => x.PackageId > 0 && x.Type == LicenseType.Complimentary).ToDictionary(x => x.PackageId, x => x.Name); - var gameIds = FetchGameIds(query, ESteamGameIdType.Sub, ESteamGameIdType.Sub); - - var sema = new SemaphoreSlim(3, 3); - - async Task workThread(uint subId) - { - try - { - sema.Wait(); - try - { - await WebRequest.RemoveLicense(bot, subId).ConfigureAwait(false); - await Task.Delay(500).ConfigureAwait(false); - } - finally - { - sema.Release(); - } - } - catch (Exception ex) - { - ASFLogger.LogGenericException(ex); - } - } - - var subIds = gameIds.Where(x => x.Type == ESteamGameIdType.Sub).Select(x => x.Id); - var tasks = subIds.Where(x => oldSubs.ContainsKey(x)).Select(x => workThread(x)); - if (tasks.Any()) - { - await Utilities.InParallel(gameIds.Select(x => WebRequest.RemoveLicense(bot, x.Id))).ConfigureAwait(false); - await Task.Delay(1000).ConfigureAwait(false); - } - - var licensesNew = await WebRequest.GetOwnedLicenses(bot).ConfigureAwait(false); - - if (licensesNew == null) - { - return bot.FormatBotResponse(Langs.NetworkError); - } - - var newSubs = licensesNew.Where(x => x.PackageId > 0 && x.Type == LicenseType.Complimentary).Select(x => x.PackageId).ToHashSet(); - - var sb = new StringBuilder(); - sb.AppendLine(bot.FormatBotResponse(Langs.MultipleLineResult)); - - foreach (var gameId in gameIds) - { - string msg; - if (gameId.Type == ESteamGameIdType.Error) - { - msg = Langs.AccountSubInvalidArg; - } - else - { - uint subId = gameId.Id; - if (oldSubs.TryGetValue(subId, out var name)) - { - bool succ = !newSubs.Contains(subId); - msg = string.Format(Langs.AccountSubRemovedItem, name, succ ? Langs.Success : Langs.Failure); - } - else - { - msg = Langs.AccountSubNotOwn; - } - } - sb.AppendLine(bot.FormatBotResponse(Langs.CookieItem, gameId.Input, msg)); - } - - return sb.ToString(); - } - - /// - /// 移除免费许可证 (多个Bot) - /// - /// - /// - /// - /// - internal static async Task ResponseRemoveFreeLicenses(string botNames, string query) - { - if (string.IsNullOrEmpty(botNames)) - { - throw new ArgumentNullException(nameof(botNames)); - } - - var bots = Bot.GetBots(botNames); - - if ((bots == null) || (bots.Count == 0)) - { - return FormatStaticResponse(Strings.BotNotFound, botNames); - } - - var results = await Utilities.InParallel(bots.Select(bot => ResponseRemoveFreeLicenses(bot, query))).ConfigureAwait(false); - - var responses = new List(results.Where(result => !string.IsNullOrEmpty(result))); - - return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; - } - - /// - /// 移除所有Demo - /// - /// - /// - internal static async Task ResponseRemoveAllDemos(Bot bot) - { - if (!bot.IsConnectedAndLoggedOn) - { - return bot.FormatBotResponse(Strings.BotNotConnected); - } - - var licensesOld = await WebRequest.GetOwnedLicenses(bot).ConfigureAwait(false); - - if (licensesOld == null) - { - return bot.FormatBotResponse(Langs.NetworkError); - } - - var oldSubs = licensesOld - .Where(static x => x.PackageId > 0 && x.Type == LicenseType.Complimentary && x?.Name?.EndsWith("Demo") == true) - .Select(static x => x.PackageId) - .ToHashSet(); - - if (oldSubs.Count == 0) - { - return bot.FormatBotResponse(Langs.AccountSubDemoSubNotFount); - } - - var sema = new SemaphoreSlim(3, 3); - - async Task workThread(uint subId) - { - try - { - sema.Wait(); - try - { - await WebRequest.RemoveLicense(bot, subId).ConfigureAwait(false); - await Task.Delay(500).ConfigureAwait(false); - } - finally - { - sema.Release(); - } - } - catch (Exception ex) - { - ASFLogger.LogGenericException(ex); - } - } - - var tasks = oldSubs.Select(x => workThread(x)); - await Utilities.InParallel(tasks).ConfigureAwait(false); - - await Task.Delay(1000).ConfigureAwait(false); - - var licensesNew = await WebRequest.GetOwnedLicenses(bot).ConfigureAwait(false); - - if (licensesNew == null) - { - return bot.FormatBotResponse(Langs.NetworkError); - } - - var newSubs = licensesNew - .Where(static x => x.PackageId > 0 && x.Type == LicenseType.Complimentary && x?.Name?.EndsWith("Demo") == true) - .Select(static x => x.PackageId) - .ToHashSet(); - var count = oldSubs.Where(x => !newSubs.Contains(x)).Count(); - - return bot.FormatBotResponse(Langs.AccountSubRemovedDemos, count); - } - - /// - /// 移除所有Demo (多个Bot) - /// - /// - /// - /// - internal static async Task ResponseRemoveAllDemos(string botNames) - { - if (string.IsNullOrEmpty(botNames)) - { - throw new ArgumentNullException(nameof(botNames)); - } - - var bots = Bot.GetBots(botNames); - - if ((bots == null) || (bots.Count == 0)) - { - return FormatStaticResponse(Strings.BotNotFound, botNames); - } - - var results = await Utilities.InParallel(bots.Select(bot => ResponseRemoveAllDemos(bot))).ConfigureAwait(false); - - var responses = new List(results.Where(result => !string.IsNullOrEmpty(result))); - - return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; - } - /// /// 获取邮箱偏好 /// diff --git a/ASFEnhance/Profile/HtmlParser.cs b/ASFEnhance/Profile/HtmlParser.cs index 9f98689b..c83fd38d 100644 --- a/ASFEnhance/Profile/HtmlParser.cs +++ b/ASFEnhance/Profile/HtmlParser.cs @@ -21,7 +21,7 @@ internal static class HtmlParser return null; } - IDocument content = response.Content; + var content = response.Content; var eleNickName = content.SelectSingleNode("//div[@class='persona_name']/span[1]"); string nickName = eleNickName?.TextContent ?? ""; @@ -62,7 +62,7 @@ internal static class HtmlParser var eleFriendsCount = content.SelectSingleNode("//a[contains(@href,'/friends/')]/span[last()]"); string? strFriendsCount = eleFriendsCount?.TextContent.Replace(",", ""); - StringBuilder result = new(); + var result = new StringBuilder(); result.AppendLine(Langs.MultipleLineResult); result.AppendLine(Langs.ProfileHeader); result.AppendLineFormat(Langs.ProfileNickname, nickName);