|
5 | 5 | using System.Linq;
|
6 | 6 | using System.Reflection;
|
7 | 7 | using System.Threading.Tasks;
|
8 |
| -using AngleSharp.Dom; |
9 | 8 | using ArchiSteamFarm.Core;
|
10 | 9 | using ArchiSteamFarm.Localization;
|
11 | 10 | using ArchiSteamFarm.Plugins.Interfaces;
|
@@ -40,64 +39,76 @@ public Task OnLoaded()
|
40 | 39 |
|
41 | 40 | return args[0].ToUpperInvariant() switch
|
42 | 41 | {
|
43 |
| - "DELETEGAME" when args.Length > 2 => ResponseDeleteGame(steamID, access, args[1], args[2]), |
| 42 | + "DELETEGAME" when args.Length > 2 => ResponseDeleteGame(steamID, access, args[1], Utilities.GetArgsAsText(args, 2, ",")), |
44 | 43 | "DELETEGAME" when args.Length > 1 => ResponseDeleteGame(bot, access, args[1]),
|
45 | 44 | _ => Task.FromResult<string?>(null)
|
46 | 45 | };
|
47 | 46 | }
|
48 | 47 |
|
49 |
| - private static async Task<string?> ResponseDeleteGame(Bot bot, EAccess access, string appIDText) |
| 48 | + private static async Task<string?> ResponseDeleteGame(Bot bot, EAccess access, string appIDsText) |
50 | 49 | {
|
51 | 50 | if (access < EAccess.Master)
|
52 | 51 | {
|
53 | 52 | return null;
|
54 | 53 | }
|
55 | 54 |
|
56 |
| - if (!uint.TryParse(appIDText, out uint appID) || (appID == 0)) |
| 55 | + HashSet<uint> appIDs = new(); |
| 56 | + var appIDTexts = appIDsText.Split(',', StringSplitOptions.RemoveEmptyEntries); |
| 57 | + foreach (var appIDText in appIDTexts) |
57 | 58 | {
|
58 |
| - return bot.Commands.FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsInvalid, nameof(appID))); |
| 59 | + if (!uint.TryParse(appIDText, out var appID) || (appID == 0) || !appIDs.Add(appID)) |
| 60 | + { |
| 61 | + return bot.Commands.FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsInvalid, appIDText)); |
| 62 | + } |
59 | 63 | }
|
60 | 64 |
|
61 |
| - const string requestDeleteGamePage = "/en/wizard/HelpWithGameIssue/?appid={0}&issueid=123"; |
62 |
| - Uri uriDeleteGamePage = new(ArchiWebHandler.SteamHelpURL, string.Format(CultureInfo.InvariantCulture, requestDeleteGamePage, appID)); |
63 |
| - using IDocument? responseDeleteGamePage = (await bot.ArchiWebHandler.UrlGetToHtmlDocumentWithSession(uriDeleteGamePage).ConfigureAwait(false))?.Content; |
64 |
| - if (responseDeleteGamePage == null) |
| 65 | + ushort successCount = 0; |
| 66 | + foreach (var appID in appIDs) |
65 | 67 | {
|
66 |
| - return bot.Commands.FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.ErrorObjectIsNull, nameof(responseDeleteGamePage))); |
| 68 | + const string RequestDeleteGamePage = "/en/wizard/HelpWithGameIssue/?appid={0}&issueid=123"; |
| 69 | + Uri uriDeleteGamePage = new(ArchiWebHandler.SteamHelpURL, string.Format(CultureInfo.InvariantCulture, RequestDeleteGamePage, appID)); |
| 70 | + using var responseDeleteGamePage = (await bot.ArchiWebHandler.UrlGetToHtmlDocumentWithSession(uriDeleteGamePage).ConfigureAwait(false))?.Content; |
| 71 | + if (responseDeleteGamePage == null) |
| 72 | + { |
| 73 | + return bot.Commands.FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.ErrorObjectIsNull, nameof(responseDeleteGamePage))); |
| 74 | + } |
| 75 | + |
| 76 | + var node = responseDeleteGamePage.SelectSingleNode("//input[@id='packageid']"); |
| 77 | + if (node == null) |
| 78 | + { |
| 79 | + return bot.Commands.FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.ErrorObjectIsNull, nameof(node))); |
| 80 | + } |
| 81 | + |
| 82 | + if (!uint.TryParse(node.GetAttribute("value"), out var packageID) || (packageID == 0)) |
| 83 | + { |
| 84 | + return bot.Commands.FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsInvalid, nameof(packageID))); |
| 85 | + } |
| 86 | + |
| 87 | + Dictionary<string, string> data = new(3) |
| 88 | + { |
| 89 | + {"packageid", packageID.ToString(CultureInfo.InvariantCulture)}, |
| 90 | + {"appid", appIDsText} |
| 91 | + }; |
| 92 | + |
| 93 | + const string RequestDeleteGame = "/en/wizard/AjaxDoPackageRemove"; |
| 94 | + var responseDeleteGame = (await bot.ArchiWebHandler.UrlPostToJsonObjectWithSession<BooleanResponse>(new Uri(ArchiWebHandler.SteamHelpURL, RequestDeleteGame), data: data, referer: uriDeleteGamePage).ConfigureAwait(false))?.Content; |
| 95 | + |
| 96 | + if (responseDeleteGame?.Success == true) |
| 97 | + successCount++; |
67 | 98 | }
|
68 | 99 |
|
69 |
| - IElement? node = responseDeleteGamePage.SelectSingleNode("//input[@id='packageid']"); |
70 |
| - if (node == null) |
71 |
| - { |
72 |
| - return bot.Commands.FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.ErrorObjectIsNull, nameof(node))); |
73 |
| - } |
74 |
| - |
75 |
| - if (!uint.TryParse(node.GetAttribute("value"), out uint packageID) || (packageID == 0)) |
76 |
| - { |
77 |
| - return bot.Commands.FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsInvalid, nameof(packageID))); |
78 |
| - } |
79 |
| - |
80 |
| - Dictionary<string, string> data = new(3) |
81 |
| - { |
82 |
| - {"packageid", packageID.ToString(CultureInfo.InvariantCulture)}, |
83 |
| - {"appid", appIDText} |
84 |
| - }; |
85 |
| - |
86 |
| - const string requestDeleteGame = "/en/wizard/AjaxDoPackageRemove"; |
87 |
| - BooleanResponse? responseDeleteGame = (await bot.ArchiWebHandler.UrlPostToJsonObjectWithSession<BooleanResponse>(new Uri(ArchiWebHandler.SteamHelpURL, requestDeleteGame), data: data, referer: uriDeleteGamePage).ConfigureAwait(false))?.Content; |
88 |
| - |
89 |
| - return bot.Commands.FormatBotResponse(responseDeleteGame?.Success == true ? Strings.Success : Strings.WarningFailed); |
| 100 | + return bot.Commands.FormatBotResponse(successCount == appIDs.Count ? Strings.Success : $"{Strings.WarningFailed}: {successCount} / {appIDs.Count}"); |
90 | 101 | }
|
91 | 102 |
|
92 |
| - private static async Task<string?> ResponseDeleteGame(ulong steamID, EAccess access, string botNames, string appIDText) |
| 103 | + private static async Task<string?> ResponseDeleteGame(ulong steamID, EAccess access, string botNames, string appIDsText) |
93 | 104 | {
|
94 |
| - HashSet<Bot>? bots = Bot.GetBots(botNames); |
| 105 | + var bots = Bot.GetBots(botNames); |
95 | 106 | if ((bots == null) || (bots.Count == 0))
|
96 | 107 | {
|
97 | 108 | return access >= EAccess.Owner ? Commands.FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null;
|
98 | 109 | }
|
99 | 110 |
|
100 |
| - IList<string?> results = await Utilities.InParallel(bots.Select(bot => ResponseDeleteGame(bot, Commands.GetProxyAccess(bot, access, steamID), appIDText))).ConfigureAwait(false); |
| 111 | + var results = await Utilities.InParallel(bots.Select(bot => ResponseDeleteGame(bot, Commands.GetProxyAccess(bot, access, steamID), appIDsText))).ConfigureAwait(false); |
101 | 112 |
|
102 | 113 | List<string> responses = new(results.Where(result => !string.IsNullOrEmpty(result))!);
|
103 | 114 |
|
|
0 commit comments