mirror of
https://github.com/barelyprofessional/KfChatDotNet.git
synced 2026-05-02 04:22:04 -04:00
Moved cache clear command to admin commands
This commit is contained in:
@@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user