Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Decline.cs
1using System.Text.RegularExpressions;
2using System.Threading.Tasks;
3
5{
9 public class Decline : CommandRegEx
10 {
14 public Decline()
15 : base(@"^decline(\s+(?'JID'[^\s]+))?$")
16 {
17 }
18
22 public override string Name => "Decline";
23
32 public override async Task Execute(ChatState State, string[] Arguments, string OrgMessage, Match Details,
33 ResponseCallbackHandler ResponseCallback)
34 {
35 int c = Arguments.Length;
36
37 if (c == 0)
38 {
39 Networking.XMPP.Events.PresenceEventArgs[] Requests = IoTGateway.Gateway.XmppClient.SubscriptionRequests;
40
41 if (Requests.Length == 0)
42 await ResponseCallback("No subscription requests pending.", string.Empty);
43 else
44 {
45 foreach (Networking.XMPP.Events.PresenceEventArgs e in Requests)
46 {
47 await e.Decline();
48 await ResponseCallback("Subscription request from `" + e.FromBareJID + "` declined.", string.Empty);
49 }
50 }
51 }
52 else
53 {
54 string JID = Arguments[0];
55
56 Networking.XMPP.Events.PresenceEventArgs e = IoTGateway.Gateway.XmppClient.GetSubscriptionRequest(JID);
57
58 if (e is null)
59 await XmppServerModule.SendErrorMessage("No pending subscription request found from `" + JID + "`.", string.Empty, ResponseCallback);
60 else
61 {
62 await e.Decline();
63 await ResponseCallback("Subscription request from `" + JID + "` declined.", string.Empty);
64 }
65 }
66 }
67
72 public override HelpItem[] GetHelp()
73 {
74 return new HelpItem[]
75 {
76 new HelpItem("accept", "Accepts all pending subscription requests, or a specific subscription request."),
77 new HelpItem("accept JID", "Accepts a specific subscription request from `JID`.")
78 };
79 }
80 }
81}
Event arguments for presence events.
async Task Decline()
Declines a subscription or unsubscription request.
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
Declines a subscription request.
Definition: Decline.cs:10
Decline()
Declines a subscription request.
Definition: Decline.cs:14
override HelpItem[] GetHelp()
Gets help about the command.
Definition: Decline.cs:72
override async Task Execute(ChatState State, string[] Arguments, string OrgMessage, Match Details, ResponseCallbackHandler ResponseCallback)
Executes the command.
Definition: Decline.cs:32
Service Module hosting the XMPP broker and its components.
delegate Task< string > ResponseCallbackHandler(string Markdown, string MessageId)
Delegate for response callback handler methods.