Skip to content

Commit

Permalink
Remove ASFE DisabledCmds support
Browse files Browse the repository at this point in the history
  • Loading branch information
Citrinate committed Mar 10, 2024
1 parent 2c77b9b commit f152400
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
10 changes: 10 additions & 0 deletions FreePackages/AdapterBridge.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Reflection;
using ArchiSteamFarm.Core;
using ArchiSteamFarm.Steam;

// ASFEnhanced Adapter https://github.com/chr233/ASFEnhanceAdapterDemoPlugin

Expand Down Expand Up @@ -29,4 +30,13 @@ public static bool InitAdapter(string pluginName, string pluginId, string? cmdPr

return false;
}

internal static string? Response(Bot bot, EAccess access, ulong steamID, string message, string[] args) {
// ASFEnhance wants to intercept commands meant for this plugin, for the purpose of it's DisabledCmds config setting.
// Seems buggy though: https://github.com/Citrinate/FreePackages/issues/28
// Therefore I'm feeding it this dummy response function, as ASFEnhance requires that cmdHandler not be null.
// This disables DisabledCmds support, but should not effect PLUGINSUPDATE command support

return null;
}
}
10 changes: 2 additions & 8 deletions FreePackages/FreePackages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,22 @@ public sealed class FreePackages : IASF, IBotModules, ISteamPICSChanges, IBotSte
public string Name => nameof(FreePackages);
public Version Version => typeof(FreePackages).Assembly.GetName().Version ?? new Version("0");
internal static GlobalCache? GlobalCache;
private bool ASFEnhanceEnabled = false;

public Task OnLoaded() {
ASF.ArchiLogger.LogGenericInfo("Free Packages ASF Plugin by Citrinate");

// ASFEnhanced Adapter https://github.com/chr233/ASFEnhanceAdapterDemoPlugin
var flag = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
var handler = typeof(Commands).GetMethod(nameof(Commands.Response), flag);
var handler = typeof(AdapterBridge).GetMethod(nameof(AdapterBridge.Response), flag);
const string pluginId = nameof(FreePackages);
const string cmdPrefix = "FREEPACKAGES";
const string repoName = "Citrinate/FreePackages";
var registered = AdapterBridge.InitAdapter(Name, pluginId, cmdPrefix, repoName, handler);
ASFEnhanceEnabled = registered;
AdapterBridge.InitAdapter(Name, pluginId, cmdPrefix, repoName, handler);

return Task.CompletedTask;
}

public Task<string?> OnBotCommand(Bot bot, EAccess access, string message, string[] args, ulong steamID = 0) {
if (ASFEnhanceEnabled) {
return Task.FromResult<string?>(null);
}

return Task.FromResult(Commands.Response(bot, access, steamID, message, args));
}

Expand Down
2 changes: 0 additions & 2 deletions FreePackages/WebRequest.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Threading;
using System.Threading.Tasks;
using ArchiSteamFarm.Core;
Expand Down

0 comments on commit f152400

Please sign in to comment.