Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Occupants.cs
1using System.Collections.Generic;
2using System.Text;
3using System.Threading.Tasks;
6
8{
13 {
17 public Occupants()
18 : base()
19 {
20 }
21
25 public override string Name => "Occupants";
26
30 public override string[] HelpParagraphs => new string[]
31 {
32 "Lists occupants in a room named `ROOM`."
33 };
34
38 public override string ParameterName => "ROOM";
39
47 public override async Task Execute(ChatState State, string[] Arguments, string OrgMessage, ResponseCallbackHandler ResponseCallback)
48 {
49 if (Gateway.MucClient is null)
50 {
51 await ResponseCallback("Multi-User Chat disabled.", string.Empty);
52 return;
53 }
54
55 Enter.ParseRoom(Arguments[0], out string RoomId, out string Domain);
56
57 if (!XmppServerModule.Instance.TryGetNickName(RoomId, Domain, out string _))
58 {
59 await ResponseCallback("Not occupant of room.", string.Empty);
60 return;
61 }
62
63 KeyValuePair<CaseInsensitiveString, Networking.XMPP.MUC.UserPresenceEventArgs>[] Occupants =
64 XmppServerModule.Instance.GetOccupants(Arguments[0]);
65
66 if ((Occupants?.Length ?? 0) == 0)
67 {
68 await ResponseCallback("No occupants in room.", string.Empty);
69 return;
70 }
71
72 StringBuilder Response = new StringBuilder();
73
74 Response.AppendLine("| Occupants in room |||||");
75 Response.AppendLine("| Nick-name | Availability | Affiliation | Role | JID |");
76 Response.AppendLine("|:----|:----|:----|:----|:----|");
77
78 foreach (KeyValuePair<CaseInsensitiveString, Networking.XMPP.MUC.UserPresenceEventArgs> P in Occupants)
79 {
80 Response.Append("| `");
81 Response.Append(P.Key.Value);
82 Response.Append("` | `");
83 Response.Append(P.Value.Availability.ToString());
84 Response.Append("` | ");
85
86 if (P.Value.Affiliation.HasValue)
87 {
88 Response.Append('`');
89 Response.Append(P.Value.Affiliation.Value.ToString());
90 Response.Append('`');
91 }
92
93 Response.Append(" | ");
94
95 if (P.Value.Role.HasValue)
96 {
97 Response.Append('`');
98 Response.Append(P.Value.Role.Value.ToString());
99 Response.Append('`');
100 }
101
102 Response.Append(" | `");
103 Response.Append(P.Value.FullJid);
104 Response.AppendLine("` |");
105 }
106
107 await ResponseCallback(Response.ToString(), string.Empty);
108 }
109 }
110}
Static class managing the runtime environment of the IoT Gateway.
Definition: Gateway.cs:126
static MultiUserChatClient MucClient
XMPP Multi-User Chat Protocol (MUC) Client.
Definition: Gateway.cs:3267
Represents a case-insensitive string.
An administrative command taking one parameter.
Asks the broker to enter a room.
Definition: Enter.cs:13
override async Task Execute(ChatState State, string[] Arguments, string OrgMessage, ResponseCallbackHandler ResponseCallback)
Executes the command.
Definition: Occupants.cs:47
override string Name
Command name
Definition: Occupants.cs:25
Occupants()
Lists occupants in a room.
Definition: Occupants.cs:17
override string ParameterName
Name of parameter.
Definition: Occupants.cs:38
override string[] HelpParagraphs
Markdown description of syntax.
Definition: Occupants.cs:30
Service Module hosting the XMPP broker and its components.
delegate Task< string > ResponseCallbackHandler(string Markdown, string MessageId)
Delegate for response callback handler methods.