Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
EnableKey.cs
1using System.Text.RegularExpressions;
2using System.Threading.Tasks;
4
6{
10 public class EnableKey : CommandRegEx
11 {
15 public EnableKey()
16 : base(@"^enable\s+key\s+(?'Key'[^\s]+)\s+(?'Accounts'\d{1,8})$")
17 {
18 }
19
23 public override string Name => "Enable";
24
33 public override async Task Execute(ChatState State, string[] Arguments, string OrgMessage, Match Details,
34 ResponseCallbackHandler ResponseCallback)
35 {
36 int c = Arguments.Length;
37 string Key = c < 2 ? string.Empty : Arguments[1];
38 int Accounts = int.Parse(c < 3 ? string.Empty : Arguments[2]);
39
40 ApiKey ApiKey = await XmppServerModule.PersistenceLayer.GetApiKey(Key);
41
42 if (ApiKey is null)
43 await XmppServerModule.SendErrorMessage("An API key with key `" + Key + "` does not exist.", string.Empty, ResponseCallback);
44 else
45 {
46 ApiKey.MaxAccounts = Accounts;
47 await Persistence.Database.Update(ApiKey);
48 await ResponseCallback("API key `" + Key + "` has been enabled for the creation of " + Accounts.ToString() + " accounts.", string.Empty);
49 }
50 }
51
56 public override HelpItem[] GetHelp()
57 {
58 return new HelpItem[]
59 {
60 new HelpItem("enable key KEY NRACCOUNTS", "Enables an existing API Key `KEY`, and allows `NRACCOUNTS` to be created with the key.")
61 };
62 }
63 }
64}
override async Task Execute(ChatState State, string[] Arguments, string OrgMessage, Match Details, ResponseCallbackHandler ResponseCallback)
Executes the command.
Definition: EnableKey.cs:33
override HelpItem[] GetHelp()
Gets help about the command.
Definition: EnableKey.cs:56
override string Name
Command name
Definition: EnableKey.cs:23
An administrative command whose syntax is validated with a regular expression.
Definition: CommandRegEx.cs:12
Contains an item of information about a command.
Definition: HelpItem.cs:9
Collection of broker accounts
Definition: Accounts.cs:14
Service Module hosting the XMPP broker and its components.
delegate Task< string > ResponseCallbackHandler(string Markdown, string MessageId)
Delegate for response callback handler methods.