Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
CommandRegEx.cs
1using System;
2using System.Reflection.Metadata;
3using System.Text.RegularExpressions;
4using System.Threading.Tasks;
5
7{
11 public abstract class CommandRegEx : IAdminCommand
12 {
13 private readonly Regex expression;
14
19 public CommandRegEx(string RegularExpression)
20 : base()
21 {
22 this.expression = new Regex(RegularExpression, RegexOptions.Singleline | RegexOptions.Compiled | RegexOptions.IgnoreCase);
23 }
24
28 public abstract string Name { get; }
29
33 public virtual string[] Aliases => null;
34
43 public virtual Task Execute(ChatState State, string[] Arguments, string OrgMessage, object Details, ResponseCallbackHandler ResponseCallback)
44 {
45 if (Details is Match Match)
46 return this.Execute(State, Arguments, OrgMessage, Match, ResponseCallback);
47 else
48 throw new ArgumentException("Expected a Regex Match object.", nameof(Details));
49 }
50
59 public abstract Task Execute(ChatState State, string[] Arguments, string OrgMessage, Match Details, ResponseCallbackHandler ResponseCallback);
60
68 public virtual bool AppliesTo(string CommandLine, string[] Arguments, out object Details)
69 {
70 Match M = this.expression.Match(CommandLine);
71 Details = M;
72 return M.Success && M.Index == 0 && M.Length == CommandLine.Length;
73 }
74
79 public abstract HelpItem[] GetHelp();
80 }
81}
An administrative command whose syntax is validated with a regular expression.
Definition: CommandRegEx.cs:12
abstract Task Execute(ChatState State, string[] Arguments, string OrgMessage, Match Details, ResponseCallbackHandler ResponseCallback)
Executes the command.
abstract string Name
Command name
Definition: CommandRegEx.cs:28
virtual string[] Aliases
Optional set of aliases. Can be null.
Definition: CommandRegEx.cs:33
virtual bool AppliesTo(string CommandLine, string[] Arguments, out object Details)
If the command is applicable to the given command line.
Definition: CommandRegEx.cs:68
virtual Task Execute(ChatState State, string[] Arguments, string OrgMessage, object Details, ResponseCallbackHandler ResponseCallback)
Executes the command.
Definition: CommandRegEx.cs:43
CommandRegEx(string RegularExpression)
An administrative command whose syntax is validated with a regular expression.
Definition: CommandRegEx.cs:19
abstract HelpItem[] GetHelp()
Gets help about the command.
Contains an item of information about a command.
Definition: HelpItem.cs:9
Basic interface for administration commands
delegate Task< string > ResponseCallbackHandler(string Markdown, string MessageId)
Delegate for response callback handler methods.