From cec3b0a10b63f707b043617d741b680d835f147c Mon Sep 17 00:00:00 2001 From: barelyprofessional <150058423+barelyprofessional@users.noreply.github.com> Date: Sat, 7 Sep 2024 19:03:37 +0800 Subject: [PATCH] Moved cache clear command to admin commands --- KfChatDotNetBot/Commands/AdminCommands.cs | 26 ++++++++++++++++++++-- KfChatDotNetBot/Commands/CacheCommands.cs | 27 ----------------------- 2 files changed, 24 insertions(+), 29 deletions(-) delete mode 100644 KfChatDotNetBot/Commands/CacheCommands.cs diff --git a/KfChatDotNetBot/Commands/AdminCommands.cs b/KfChatDotNetBot/Commands/AdminCommands.cs index ddb8f41..f55e16a 100644 --- a/KfChatDotNetBot/Commands/AdminCommands.cs +++ b/KfChatDotNetBot/Commands/AdminCommands.cs @@ -1,4 +1,5 @@ -using System.Text.RegularExpressions; +using System.Runtime.Caching; +using System.Text.RegularExpressions; using Humanizer; using KfChatDotNetBot.Models.DbModels; using KfChatDotNetBot.Settings; @@ -125,7 +126,7 @@ public class GmKasinoListCommand : ICommand } } -public class ToggleLiveStatusCommand : ICommand +public class ToggleLiveStatusAdminCommand : ICommand { public List Patterns => [ new Regex(@"^admin toggle livestatus$") @@ -140,4 +141,25 @@ public class ToggleLiveStatusCommand : ICommand botInstance.SendChatMessage($"IsBmjLive => {botInstance.BotServices.IsBmjLive}", true); } +} + +public class CacheClearAdminCommand : ICommand +{ + public List 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); + } } \ No newline at end of file diff --git a/KfChatDotNetBot/Commands/CacheCommands.cs b/KfChatDotNetBot/Commands/CacheCommands.cs deleted file mode 100644 index a6be27d..0000000 --- a/KfChatDotNetBot/Commands/CacheCommands.cs +++ /dev/null @@ -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 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); - } -} \ No newline at end of file