mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-05 08:30:18 +00:00
Extract addlicense logic to actions
This commit is contained in:
@@ -78,6 +78,30 @@ public sealed class Actions : IAsyncDisposable, IDisposable {
|
||||
}
|
||||
}
|
||||
|
||||
[PublicAPI]
|
||||
public async Task<(EResult Result, IReadOnlyCollection<uint>? GrantedApps, IReadOnlyCollection<uint>? GrantedPackages)> AddFreeLicenseApp(uint appID) {
|
||||
ArgumentOutOfRangeException.ThrowIfZero(appID);
|
||||
|
||||
SteamApps.FreeLicenseCallback callback;
|
||||
|
||||
try {
|
||||
callback = await Bot.SteamApps.RequestFreeLicense(appID).ToLongRunningTask().ConfigureAwait(false);
|
||||
} catch (Exception e) {
|
||||
Bot.ArchiLogger.LogGenericWarningException(e);
|
||||
|
||||
return (EResult.Timeout, null, null);
|
||||
}
|
||||
|
||||
return (callback.Result, callback.GrantedApps, callback.GrantedPackages);
|
||||
}
|
||||
|
||||
[PublicAPI]
|
||||
public async Task<(EResult Result, EPurchaseResultDetail PurchaseResultDetail)> AddFreeLicensePackage(uint subID) {
|
||||
ArgumentOutOfRangeException.ThrowIfZero(subID);
|
||||
|
||||
return await Bot.ArchiWebHandler.AddFreeLicense(subID).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[PublicAPI]
|
||||
public static string? Encrypt(ArchiCryptoHelper.ECryptoMethod cryptoMethod, string stringToEncrypt) {
|
||||
if (!Enum.IsDefined(cryptoMethod)) {
|
||||
|
||||
@@ -623,7 +623,7 @@ public sealed class Commands {
|
||||
}
|
||||
|
||||
switch (type.ToUpperInvariant()) {
|
||||
case "A" or "APP":
|
||||
case "A" or "APP": {
|
||||
HashSet<uint>? packageIDs = ASF.GlobalDatabase?.GetPackageIDs(gameID, Bot.OwnedPackageIDs.Keys, 1);
|
||||
|
||||
if (packageIDs is { Count: > 0 }) {
|
||||
@@ -632,32 +632,34 @@ public sealed class Commands {
|
||||
break;
|
||||
}
|
||||
|
||||
SteamApps.FreeLicenseCallback callback;
|
||||
(EResult result, IReadOnlyCollection<uint>? grantedApps, IReadOnlyCollection<uint>? grantedPackages) = await Bot.Actions.AddFreeLicenseApp(gameID).ConfigureAwait(false);
|
||||
|
||||
try {
|
||||
callback = await Bot.SteamApps.RequestFreeLicense(gameID).ToLongRunningTask().ConfigureAwait(false);
|
||||
} catch (Exception e) {
|
||||
Bot.ArchiLogger.LogGenericWarningException(e);
|
||||
if (((grantedApps == null) || (grantedApps.Count == 0)) && ((grantedPackages == null) || (grantedPackages.Count == 0))) {
|
||||
response.AppendLine(FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotAddLicense, $"app/{gameID}", EResult.Timeout)));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
response.AppendLine(FormatBotResponse((callback.GrantedApps.Count > 0) || (callback.GrantedPackages.Count > 0) ? string.Format(CultureInfo.CurrentCulture, Strings.BotAddLicenseWithItems, $"app/{gameID}", callback.Result, string.Join(", ", callback.GrantedApps.Select(static appID => $"app/{appID}").Union(callback.GrantedPackages.Select(static subID => $"sub/{subID}")))) : string.Format(CultureInfo.CurrentCulture, Strings.BotAddLicense, $"app/{gameID}", callback.Result)));
|
||||
grantedApps ??= Array.Empty<uint>();
|
||||
grantedPackages ??= Array.Empty<uint>();
|
||||
|
||||
response.AppendLine(FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotAddLicenseWithItems, $"app/{gameID}", result, string.Join(", ", grantedApps.Select(static appID => $"app/{appID}").Union(grantedPackages.Select(static subID => $"sub/{subID}"))))));
|
||||
|
||||
break;
|
||||
default:
|
||||
}
|
||||
default: {
|
||||
if (Bot.OwnedPackageIDs.ContainsKey(gameID)) {
|
||||
response.AppendLine(FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotAddLicense, $"sub/{gameID}", $"{EResult.Fail}/{EPurchaseResultDetail.AlreadyPurchased}")));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
(EResult result, EPurchaseResultDetail purchaseResult) = await Bot.ArchiWebHandler.AddFreeLicense(gameID).ConfigureAwait(false);
|
||||
(EResult result, EPurchaseResultDetail purchaseResult) = await Bot.Actions.AddFreeLicensePackage(gameID).ConfigureAwait(false);
|
||||
|
||||
response.AppendLine(FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotAddLicense, $"sub/{gameID}", $"{result}/{purchaseResult}")));
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user