mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 13:45:10 +00:00
[ADD] Add a few basic MUC commands
This commit is contained in:
parent
d4371ac30b
commit
7f7ab41afa
5 changed files with 70 additions and 14 deletions
|
|
@ -21,12 +21,6 @@ AdminsCallback(XMPPCommandManager *m, char *from, XMLElement *form, XMLElement *
|
||||||
XMLElement *title;
|
XMLElement *title;
|
||||||
XMLElement *reported, *item, *field, *value, *txt;
|
XMLElement *reported, *item, *field, *value, *txt;
|
||||||
|
|
||||||
if (!ParseeIsAdmin(data, trimmed))
|
|
||||||
{
|
|
||||||
SetNote("error", "User is not authorised to execute command.");
|
|
||||||
Free(trimmed);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Free(trimmed);
|
Free(trimmed);
|
||||||
x = XMLCreateTag("x");
|
x = XMLCreateTag("x");
|
||||||
title = XMLCreateTag("title");
|
title = XMLCreateTag("title");
|
||||||
|
|
|
||||||
49
src/XMPPCommands/MUCInformation.c
Normal file
49
src/XMPPCommands/MUCInformation.c
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
#include <Cytoplasm/HashMap.h>
|
||||||
|
#include <Cytoplasm/Memory.h>
|
||||||
|
#include <Cytoplasm/Json.h>
|
||||||
|
#include <Cytoplasm/Util.h>
|
||||||
|
#include <Cytoplasm/Str.h>
|
||||||
|
#include <Cytoplasm/Log.h>
|
||||||
|
|
||||||
|
#include <XMPPFormTool.h>
|
||||||
|
#include <XMPPCommand.h>
|
||||||
|
#include <Parsee.h>
|
||||||
|
#include <XMPP.h>
|
||||||
|
#include <XML.h>
|
||||||
|
|
||||||
|
void
|
||||||
|
MUCInformationID(XMPPCommandManager *m, char *from, XMLElement *form, XMLElement *out)
|
||||||
|
{
|
||||||
|
ParseeData *data = XMPPGetManagerCookie(m);
|
||||||
|
char *muc = ParseeTrimJID(from);
|
||||||
|
char *chat_id = ParseeGetFromMUCID(data, muc);
|
||||||
|
char *room_id = ParseeGetRoomID(data, chat_id);
|
||||||
|
char *msg = StrConcat(5,
|
||||||
|
"The MUC ", muc, " is bridged to ", room_id, "."
|
||||||
|
);
|
||||||
|
|
||||||
|
SetNote("info", msg);
|
||||||
|
|
||||||
|
Free(muc);
|
||||||
|
Free(msg);
|
||||||
|
Free(room_id);
|
||||||
|
Free(chat_id);
|
||||||
|
(void) form;
|
||||||
|
}
|
||||||
|
void
|
||||||
|
MUCInformationCID(XMPPCommandManager *m, char *from, XMLElement *form, XMLElement *out)
|
||||||
|
{
|
||||||
|
ParseeData *data = XMPPGetManagerCookie(m);
|
||||||
|
char *muc = ParseeTrimJID(from);
|
||||||
|
char *chat_id = ParseeGetFromMUCID(data, muc);
|
||||||
|
char *msg = StrConcat(5,
|
||||||
|
"The MUC ", muc, "'s internal ID is ", chat_id, "."
|
||||||
|
);
|
||||||
|
|
||||||
|
SetNote("info", msg);
|
||||||
|
|
||||||
|
Free(muc);
|
||||||
|
Free(msg);
|
||||||
|
Free(chat_id);
|
||||||
|
(void) form;
|
||||||
|
}
|
||||||
|
|
@ -26,13 +26,6 @@ StatusCallback(XMPPCommandManager *m, char *from, XMLElement *form, XMLElement *
|
||||||
XMLElement *x;
|
XMLElement *x;
|
||||||
XMLElement *title, *txt;
|
XMLElement *title, *txt;
|
||||||
|
|
||||||
if (!ParseeIsAdmin(data, trimmed))
|
|
||||||
{
|
|
||||||
SetNote("error", "User is not authorised to execute command.");
|
|
||||||
|
|
||||||
Free(trimmed);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Free(trimmed);
|
Free(trimmed);
|
||||||
x = XMLCreateTag("x");
|
x = XMLCreateTag("x");
|
||||||
title = XMLCreateTag("title");
|
title = XMLCreateTag("title");
|
||||||
|
|
|
||||||
|
|
@ -387,6 +387,16 @@ IQIsCommandList(ParseeData *args, XMLElement *stanza)
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
static bool
|
||||||
|
IsInMUC(ParseeData *data, char *jid)
|
||||||
|
{
|
||||||
|
char *trimmed = ParseeTrimJID(jid);
|
||||||
|
char *chat_id = ParseeGetFromMUCID(data, trimmed);
|
||||||
|
|
||||||
|
Free(trimmed);
|
||||||
|
Free(chat_id);
|
||||||
|
return !!chat_id;
|
||||||
|
}
|
||||||
void
|
void
|
||||||
IQGet(ParseeData *args, XMLElement *stanza, XMPPThread *thr)
|
IQGet(ParseeData *args, XMLElement *stanza, XMPPThread *thr)
|
||||||
{
|
{
|
||||||
|
|
@ -401,19 +411,27 @@ IQGet(ParseeData *args, XMLElement *stanza, XMPPThread *thr)
|
||||||
if (IQIsCommandList(args, stanza))
|
if (IQIsCommandList(args, stanza))
|
||||||
{
|
{
|
||||||
XMLElement *iq_reply = XMLCreateTag("iq");
|
XMLElement *iq_reply = XMLCreateTag("iq");
|
||||||
|
char *trimmed = ParseeTrimJID(from);
|
||||||
|
|
||||||
XMLAddAttr(iq_reply, "type", "result");
|
XMLAddAttr(iq_reply, "type", "result");
|
||||||
XMLAddAttr(iq_reply, "from", to);
|
XMLAddAttr(iq_reply, "from", to);
|
||||||
XMLAddAttr(iq_reply, "to", from);
|
XMLAddAttr(iq_reply, "to", from);
|
||||||
XMLAddAttr(iq_reply, "id", id);
|
XMLAddAttr(iq_reply, "id", id);
|
||||||
{
|
{
|
||||||
XMLElement *q = XMLCreateTag("query");
|
XMLElement *q = XMLCreateTag("query");
|
||||||
|
char *parsee_muc_jid = StrConcat(3, trimmed, "/", "parsee");
|
||||||
XMLAddAttr(q, "xmlns", "http://jabber.org/protocol/disco#items");
|
XMLAddAttr(q, "xmlns", "http://jabber.org/protocol/disco#items");
|
||||||
XMLAddAttr(q, "node", "http://jabber.org/protocol/commands");
|
XMLAddAttr(q, "node", "http://jabber.org/protocol/commands");
|
||||||
XMPPShoveCommandList(thr->info->m, to, q, stanza);
|
XMPPShoveCommandList(thr->info->m,
|
||||||
|
IsInMUC(args, from) ? parsee_muc_jid : to,
|
||||||
|
q, stanza
|
||||||
|
);
|
||||||
XMLAddChild(iq_reply, q);
|
XMLAddChild(iq_reply, q);
|
||||||
|
Free(parsee_muc_jid);
|
||||||
}
|
}
|
||||||
XMPPSendStanza(jabber, iq_reply, args->config->max_stanza_size);
|
XMPPSendStanza(jabber, iq_reply, args->config->max_stanza_size);
|
||||||
XMLFreeElement(iq_reply);
|
XMLFreeElement(iq_reply);
|
||||||
|
Free(trimmed);
|
||||||
}
|
}
|
||||||
else if (XMLookForTKV(stanza, "vCard", "xmlns", "vcard-temp"))
|
else if (XMLookForTKV(stanza, "vCard", "xmlns", "vcard-temp"))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -43,5 +43,7 @@ typedef enum XMPPCommandFlags {
|
||||||
XMPPSetFormInstruction(cmd, "Add a server to whitelist"); \
|
XMPPSetFormInstruction(cmd, "Add a server to whitelist"); \
|
||||||
}) \
|
}) \
|
||||||
XMPP_COMMAND(WhitelistCallback, XMPPCMD_ADMINS, "wl", "Get Parsee's chat whitelist", {}) \
|
XMPP_COMMAND(WhitelistCallback, XMPPCMD_ADMINS, "wl", "Get Parsee's chat whitelist", {}) \
|
||||||
|
XMPP_COMMAND(MUCInformationID, XMPPCMD_MUC, "muc-info-id", "Get bridged Matrix room ID", {}) \
|
||||||
|
XMPP_COMMAND(MUCInformationCID, XMPPCMD_MUC, "muc-info-cid", "Get MUC's internal ID", {}) \
|
||||||
|
|
||||||
XMPPCOMMANDS
|
XMPPCOMMANDS
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue