Moved cache clear command to admin commands

This commit is contained in:
barelyprofessional
2024-09-07 19:03:37 +08:00
parent 2accae84cf
commit cec3b0a10b
2 changed files with 24 additions and 29 deletions

View File

@@ -1,4 +1,5 @@
using System.Text.RegularExpressions; using System.Runtime.Caching;
using System.Text.RegularExpressions;
using Humanizer; using Humanizer;
using KfChatDotNetBot.Models.DbModels; using KfChatDotNetBot.Models.DbModels;
using KfChatDotNetBot.Settings; using KfChatDotNetBot.Settings;
@@ -125,7 +126,7 @@ public class GmKasinoListCommand : ICommand
} }
} }
public class ToggleLiveStatusCommand : ICommand public class ToggleLiveStatusAdminCommand : ICommand
{ {
public List<Regex> Patterns => [ public List<Regex> Patterns => [
new Regex(@"^admin toggle livestatus$") new Regex(@"^admin toggle livestatus$")
@@ -140,4 +141,25 @@ public class ToggleLiveStatusCommand : ICommand
botInstance.SendChatMessage($"IsBmjLive => {botInstance.BotServices.IsBmjLive}", true); botInstance.SendChatMessage($"IsBmjLive => {botInstance.BotServices.IsBmjLive}", true);
} }
}
public class CacheClearAdminCommand : ICommand
{
public List<Regex> Patterns => [
new Regex("^admin cache clear$")
];
public string? HelpText => null;
public UserRight RequiredRight => UserRight.Admin;
public TimeSpan Timeout => TimeSpan.FromSeconds(10);
public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments, CancellationToken ctx)
{
var cacheKeys = MemoryCache.Default.Select(kvp => kvp.Key).ToList();
foreach (var cacheKey in cacheKeys)
{
MemoryCache.Default.Remove(cacheKey);
}
botInstance.SendChatMessage("Cache wiped", true);
}
} }

View File

@@ -1,27 +0,0 @@
using System.Runtime.Caching;
using System.Text.RegularExpressions;
using KfChatDotNetBot.Models.DbModels;
using KfChatDotNetWsClient.Models.Events;
namespace KfChatDotNetBot.Commands;
public class CacheClearCommand : ICommand
{
public List<Regex> Patterns => [
new Regex("^cache clear")
];
public string? HelpText => null;
public UserRight RequiredRight => UserRight.Admin;
public TimeSpan Timeout => TimeSpan.FromSeconds(10);
public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments, CancellationToken ctx)
{
var cacheKeys = MemoryCache.Default.Select(kvp => kvp.Key).ToList();
foreach (var cacheKey in cacheKeys)
{
MemoryCache.Default.Remove(cacheKey);
}
botInstance.SendChatMessage("Cache wiped", true);
}
}