Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DevSplash committed Mar 20, 2024
1 parent 442bc3e commit 4d89262
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
52 changes: 28 additions & 24 deletions AutoClaimStickers/AutoClaimStickers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading;
using System.Threading.Tasks;
using ArchiSteamFarm.Core;
using ArchiSteamFarm.Localization;
using ArchiSteamFarm.Plugins.Interfaces;
using ArchiSteamFarm.Steam;
using ArchiSteamFarm.Steam.Integration;
Expand All @@ -33,34 +34,33 @@ public Task OnLoaded() {
return Task.CompletedTask;
}
public Task OnASFInit(IReadOnlyDictionary<string, JsonElement>? additionalConfigProperties = null) {
if (additionalConfigProperties == null) {
return Task.CompletedTask;
}
if (AutoClaimTimer == null) {
throw new InvalidOperationException(nameof(AutoClaimTimer));
}
foreach ((string configProperty, JsonElement configValue) in additionalConfigProperties) {
switch (configProperty) {
case $"{nameof(AutoClaimStickers)}{nameof(Interval)}" when configValue.ValueKind == JsonValueKind.Number:
if (configValue.TryGetUInt16(out ushort iterval)) {
lock (AutoClaimSemaphore) {
Interval = iterval;
if (additionalConfigProperties != null) {
foreach ((string configProperty, JsonElement configValue) in additionalConfigProperties) {
switch (configProperty) {
case $"{nameof(AutoClaimStickers)}{nameof(Interval)}" when configValue.ValueKind == JsonValueKind.Number:
if (configValue.TryGetUInt16(out ushort iterval)) {
lock (AutoClaimSemaphore) {
Interval = iterval;
}
}
}
break;
case $"{nameof(AutoClaimStickers)}{nameof(Blacklist)}" when configValue.ValueKind == JsonValueKind.Array:
ImmutableHashSet<string>? blackList = null;
try {
blackList = configValue.EnumerateArray().Select(item => item.GetString() ?? string.Empty).Where(item => !string.IsNullOrWhiteSpace(item)).ToImmutableHashSet();
lock (Blacklist) {
Blacklist = blackList;
break;
case $"{nameof(AutoClaimStickers)}{nameof(Blacklist)}" when configValue.ValueKind == JsonValueKind.Array:
ImmutableHashSet<string>? blackList = null;
try {
blackList = configValue.EnumerateArray().Select(item => item.GetString() ?? string.Empty).Where(item => !string.IsNullOrWhiteSpace(item)).ToImmutableHashSet();
lock (Blacklist) {
Blacklist = blackList;
}
} catch (Exception) {
ASF.ArchiLogger.LogGenericWarning($"Invalid config property: {configProperty}");
}
} catch (Exception) {
ASF.ArchiLogger.LogGenericWarning($"Invalid config property: {configProperty}");
}
break;
default:
break;
break;
default:
break;
}
}
}
lock (AutoClaimSemaphore) {
Expand All @@ -72,11 +72,13 @@ public Task OnASFInit(IReadOnlyDictionary<string, JsonElement>? additionalConfig
}
private async Task AutoClaim() {
if (!await AutoClaimSemaphore.WaitAsync(0).ConfigureAwait(false)) {
ASF.ArchiLogger.LogGenericWarning($"[{nameof(AutoClaimStickers)}] AutoClaim task is already running!");
return;
}
try {
HashSet<Bot>? bots = Bot.GetBots("ASF");
if (bots == null) {
if (bots == null || bots.Count == 0) {
ASF.ArchiLogger.LogGenericWarning($"[{nameof(AutoClaimStickers)}] Couldn't find any bot!");
return;
}
List<Task> tasks = [];
Expand All @@ -95,6 +97,8 @@ private async Task AutoClaim() {
_ = BotSemaphore.Release();
}
}));
} else {
ASF.ArchiLogger.LogGenericWarning($"[{bot.BotName}] {Strings.BotNotConnected}");
}
}
await Task.WhenAll([.. tasks]).ConfigureAwait(false);
Expand Down
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.4</Version>
<Version>1.0.1.5</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down

0 comments on commit 4d89262

Please sign in to comment.