Skip to content

Commit

Permalink
Add automatic update support
Browse files Browse the repository at this point in the history
Update ArchiSteamFarm to 6.0.1.21
  • Loading branch information
DevSplash committed Mar 30, 2024
1 parent 4d89262 commit 88dd86f
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ArchiSteamFarm
Submodule ArchiSteamFarm updated 274 files
59 changes: 58 additions & 1 deletion AutoClaimStickers/AutoClaimStickers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,28 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Composition;
using System.Globalization;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using ArchiSteamFarm.Core;
using ArchiSteamFarm.Localization;
using ArchiSteamFarm.Plugins.Interfaces;
using ArchiSteamFarm.Steam;
using ArchiSteamFarm.Steam.Integration;
using ArchiSteamFarm.Web.GitHub;
using ArchiSteamFarm.Web.GitHub.Data;
using ArchiSteamFarm.Web.Responses;

namespace AutoClaimStickers;

[Export(typeof(IPlugin))]
internal sealed class AutoClaimStickers : IPlugin, IASF, IDisposable {
internal sealed partial class AutoClaimStickers : IASF, IGitHubPluginUpdates, IDisposable {
public string Name => nameof(AutoClaimStickers);
public string RepositoryName => "DevSplash/ASFAutoClaimStickers";
public Version Version => typeof(AutoClaimStickers).Assembly.GetName().Version ?? throw new InvalidOperationException(nameof(Version));
private static Uri SteamApiURL => new("https://api.steampowered.com");
private static Uri RefererURL => new(ArchiWebHandler.SteamStoreURL, "/category/casual");
Expand All @@ -28,6 +33,10 @@ internal sealed class AutoClaimStickers : IPlugin, IASF, IDisposable {
private static readonly SemaphoreSlim AutoClaimSemaphore = new(1, 1);
private static readonly SemaphoreSlim BotSemaphore = new(3, 3);
private static readonly JsonSerializerOptions SerializerOptions = new() { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull };
[GeneratedRegex(@"\[ASFMinimumVersion\]:(\d+\.\d+\.\d+\.\d+)")]
private static partial Regex ASFMinimumVersionRegex();
[GeneratedRegex(@"\[ASFMaximumVersion\]:(\d+\.\d+\.\d+\.\d+)")]
private static partial Regex ASFMaximumVersionRegex();

public Task OnLoaded() {
AutoClaimTimer = new(OnAutoClaimTimer);
Expand Down Expand Up @@ -139,5 +148,53 @@ private static async Task<bool> CanClaimItem(Bot bot, string token) {
return (!string.IsNullOrWhiteSpace(result?.Response?.CommunityItemId), result?.Response);
}
private async void OnAutoClaimTimer(object? state = null) => await AutoClaim().ConfigureAwait(false);
public async Task<Uri?> GetTargetReleaseURL(Version asfVersion, string asfVariant, bool asfUpdate, bool stable, bool forced) {
ArgumentNullException.ThrowIfNull(asfVersion);
ArgumentException.ThrowIfNullOrEmpty(asfVariant);
if (string.IsNullOrEmpty(RepositoryName)) {
ASF.ArchiLogger.LogGenericError(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, nameof(RepositoryName)));
return null;
}
ImmutableList<ReleaseResponse>? releases = await GitHubService.GetReleases(RepositoryName, 100).ConfigureAwait(false);
if (releases == null) {
return null;
}
foreach (ReleaseResponse release in releases) {
if (!stable || !release.IsPreRelease) {
Version newVersion = new(release.Tag);
if (!forced) {
if (Version >= newVersion) {
continue;
}
Match match = ASFMinimumVersionRegex().Match(release.MarkdownBody);
if (!match.Success || match.Groups.Count != 2) {
continue;
}
Version minimumVersion = new(match.Groups[1].Value);
if (asfVersion < minimumVersion) {
continue;
}
match = ASFMaximumVersionRegex().Match(release.MarkdownBody);
if (match.Success && match.Groups.Count == 2) {
Version maximumVersion = new(match.Groups[1].Value);
if (asfVersion > maximumVersion) {
continue;
}
}
}
if (release.Assets.Count == 0) {
continue;
}
ReleaseAsset? asset = await ((IGitHubPluginUpdates) this).GetTargetReleaseAsset(asfVersion, asfVariant, newVersion, release.Assets).ConfigureAwait(false);
if ((asset == null) || !release.Assets.Contains(asset)) {
continue;
}
ASF.ArchiLogger.LogGenericInfo(string.Format(CultureInfo.CurrentCulture, Strings.PluginUpdateFound, Name, Version, newVersion));
return asset.DownloadURL;
}
}
ASF.ArchiLogger.LogGenericInfo($"No update available for {Name} plugin");
return null;
}
public void Dispose() => AutoClaimTimer?.Dispose();
}
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<PropertyGroup>
<PluginName>AutoClaimStickers</PluginName>
<Version>1.0.1.5</Version>
<Version>1.0.2.1</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down

0 comments on commit 88dd86f

Please sign in to comment.