mirror of
https://github.com/barelyprofessional/KfChatDotNet.git
synced 2026-05-02 04:22:04 -04:00
Updated commands to remove the hide from help property, instead set the help text to null for whenever that eventually gets implemented.
Also refactored the way tasks are handled so instead of adding to an array and checking in on them next time someone sends a message, it instead delegates it to a very basic async handler that'll await the command, report errors and kill the task if it takes too long.
This commit is contained in:
@@ -13,10 +13,10 @@ public class EditTestCommand : ICommand
|
||||
new Regex("^test edit (?<msg>.+)")
|
||||
];
|
||||
|
||||
public string HelpText => "Test the editing functionality";
|
||||
public bool HideFromHelp => true;
|
||||
public string? HelpText => null;
|
||||
public UserRight RequiredRight => UserRight.Admin;
|
||||
|
||||
// Increased timeout as it has to wait for Sneedchat to echo the message and that can be slow sometimes
|
||||
public TimeSpan Timeout => TimeSpan.FromSeconds(60);
|
||||
public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments, CancellationToken ctx)
|
||||
{
|
||||
var logger = LogManager.GetCurrentClassLogger();
|
||||
@@ -49,4 +49,36 @@ public class EditTestCommand : ICommand
|
||||
await Task.Delay(delay, ctx);
|
||||
botInstance.KfClient.DeleteMessage(status.ChatMessageId!.Value);
|
||||
}
|
||||
}
|
||||
|
||||
public class TimeoutTestCommand : ICommand
|
||||
{
|
||||
public List<Regex> Patterns => [
|
||||
new Regex("^test timeout$")
|
||||
];
|
||||
|
||||
public string? HelpText => null;
|
||||
public UserRight RequiredRight => UserRight.Admin;
|
||||
// Increased timeout as it has to wait for Sneedchat to echo the message and that can be slow sometimes
|
||||
public TimeSpan Timeout => TimeSpan.FromSeconds(15);
|
||||
public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments, CancellationToken ctx)
|
||||
{
|
||||
await Task.Delay(TimeSpan.FromMinutes(1), ctx);
|
||||
}
|
||||
}
|
||||
|
||||
public class ExceptionTestCommand : ICommand
|
||||
{
|
||||
public List<Regex> Patterns => [
|
||||
new Regex("^test exception$")
|
||||
];
|
||||
|
||||
public string? HelpText => null;
|
||||
public UserRight RequiredRight => UserRight.Admin;
|
||||
// Increased timeout as it has to wait for Sneedchat to echo the message and that can be slow sometimes
|
||||
public TimeSpan Timeout => TimeSpan.FromSeconds(15);
|
||||
public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments, CancellationToken ctx)
|
||||
{
|
||||
throw new Exception("Caused by the test exception command");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user