-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
104 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "ArchiSteamFarm"] | ||
path = ArchiSteamFarm | ||
url = https://github.com/JustArchiNET/ArchiSteamFarm |
Submodule ArchiSteamFarm
added at
945e94
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Composition; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Threading.Tasks; | ||
using AngleSharp.Dom; | ||
using ArchiSteamFarm; | ||
using ArchiSteamFarm.Json; | ||
using ArchiSteamFarm.Localization; | ||
using ArchiSteamFarm.Plugins; | ||
using JetBrains.Annotations; | ||
|
||
namespace GameRemover { | ||
// ReSharper disable once UnusedMember.Global | ||
[Export(typeof(IPlugin))] | ||
[UsedImplicitly] | ||
public class GameRemover : IBotCommand { | ||
public void OnLoaded() { | ||
ASF.ArchiLogger.LogGenericInfo(nameof(GameRemover) + " is loaded!"); | ||
} | ||
|
||
public string Name => nameof(GameRemover); | ||
public Version Version => Assembly.GetExecutingAssembly().GetName().Version ?? throw new InvalidOperationException(nameof(Version)); | ||
|
||
public async Task<string?> OnBotCommand(Bot bot, ulong steamID, string message, string[] args) { | ||
return args[0].ToUpperInvariant() switch { | ||
"DELETEGAME" when args.Length > 2 => await ResponseDeleteGame(steamID, args[1], args[2]), | ||
"DELETEGAME" when args.Length > 1 => await ResponseDeleteGame(bot, steamID, args[1]).ConfigureAwait(false), | ||
_ => null | ||
}; | ||
} | ||
|
||
private static async Task<string?> ResponseDeleteGame(Bot bot, ulong steamID, string appIDText) { | ||
if (!bot.HasAccess(steamID, BotConfig.EAccess.Master)) { | ||
return null; | ||
} | ||
|
||
if (!uint.TryParse(appIDText, out uint appID) || (appID == 0)) { | ||
return bot.Commands.FormatBotResponse(string.Format(Strings.ErrorIsInvalid, nameof(appID))); | ||
} | ||
|
||
const string requestDeleteGamePage = "/en/wizard/HelpWithGameIssue/?appid={0}&issueid=123"; | ||
using IDocument? responseDeleteGamePage = (await bot.ArchiWebHandler.UrlGetToHtmlDocumentWithSession(ArchiWebHandler.SteamHelpURL, string.Format(requestDeleteGamePage, appID)).ConfigureAwait(false))?.Content; | ||
if (responseDeleteGamePage == null) { | ||
return bot.Commands.FormatBotResponse(string.Format(Strings.ErrorObjectIsNull, nameof(responseDeleteGamePage))); | ||
} | ||
|
||
IElement? node = responseDeleteGamePage.SelectSingleNode("//input[@id='packageid']"); | ||
if (node == null) { | ||
return bot.Commands.FormatBotResponse(string.Format(Strings.ErrorObjectIsNull, nameof(node))); | ||
} | ||
|
||
if (!uint.TryParse(node.GetAttribute("value"), out uint packageID) || (packageID == 0)) { | ||
return bot.Commands.FormatBotResponse(string.Format(Strings.ErrorIsInvalid, nameof(packageID))); | ||
} | ||
|
||
Dictionary<string, string> data = new(3) { | ||
{"packageid", packageID.ToString()}, | ||
{"appid", appIDText} | ||
}; | ||
|
||
const string requestDeleteGame = "/en/wizard/AjaxDoPackageRemove"; | ||
Steam.BooleanResponse? responseDeleteGame = (await bot.ArchiWebHandler.UrlPostToJsonObjectWithSession<Steam.BooleanResponse>(ArchiWebHandler.SteamHelpURL, requestDeleteGame, data: data, referer: $"https://help.steampowered.com/en/wizard/HelpWithGameIssue/?appid={appID}&issueid=123").ConfigureAwait(false))?.Content; | ||
|
||
return bot.Commands.FormatBotResponse(responseDeleteGame?.Success == true ? Strings.Success : Strings.WarningFailed); | ||
} | ||
|
||
private static async Task<string?> ResponseDeleteGame(ulong steamID, string botNames, string appIDText) { | ||
HashSet<Bot>? bots = Bot.GetBots(botNames); | ||
if ((bots == null) || (bots.Count == 0)) { | ||
return ASF.IsOwner(steamID) ? Commands.FormatStaticResponse(string.Format(Strings.BotNotFound, botNames)) : null; | ||
} | ||
|
||
IList<string?> results = await Utilities.InParallel(bots.Select(bot => ResponseDeleteGame(bot, steamID, appIDText))).ConfigureAwait(false); | ||
|
||
List<string> responses = new(results.Where(result => !string.IsNullOrEmpty(result))!); | ||
return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<AssemblyVersion>1.1.0.0</AssemblyVersion> | ||
<FileVersion>1.1.0.0</FileVersion> | ||
<Nullable>enable</Nullable> | ||
<TargetFrameworks>net5.0;net48</TargetFrameworks> | ||
<LangVersion>latest</LangVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="AngleSharp" Version="*" IncludeAssets="compile" /> | ||
<PackageReference Include="JetBrains.Annotations" Version="*" IncludeAssets="compile" /> | ||
<PackageReference Include="System.Composition.AttributedModel" Version="*" IncludeAssets="compile" /> | ||
<ProjectReference Include="..\ArchiSteamFarm\ArchiSteamFarm\ArchiSteamFarm.csproj" Private="false" ExcludeAssets="compile" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.