[ADD] No-fly, forms

This commit is contained in:
LDA 2024-07-14 11:42:30 +02:00
commit df394172ec
11 changed files with 338 additions and 52 deletions

View 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
AddAdminCallback(XMPPCommandManager *m, char *from, XMLElement *form, XMLElement *out)
{
ParseeData *data = XMPPGetManagerCookie(m);
char *trimmed = ParseeTrimJID(from);
char *glob = NULL;
DbRef *ref;
Array *admins;
GetFieldValue(glob, "glob", form);
if (!ParseeIsAdmin(data, trimmed))
{
SetNote("error", "User is not authorised to execute command.");
Free(trimmed);
return;
}
if (!glob)
{
SetNote("error", "No glob found.");
Free(trimmed);
return;
}
Free(trimmed);
SetNote("info", "Glob sucessfully added.");
ref = DbLock(data->db, 1, "admins");
admins = GrabArray(DbJson(ref), 1, "admins");
ArrayAdd(admins, JsonValueString(glob));
DbUnlock(data->db, ref);
}

View file

@ -0,0 +1,46 @@
#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
AddNoflyCallback(XMPPCommandManager *m, char *from, XMLElement *form, XMLElement *out)
{
ParseeData *data = XMPPGetManagerCookie(m);
char *trimmed = ParseeTrimJID(from);
char *entity = NULL, *reason = NULL;
GetFieldValue(entity, "entity", form);
GetFieldValue(reason, "reason", form);
if (!ParseeIsAdmin(data, trimmed))
{
SetNote("error", "User is not authorised to execute command.");
Free(trimmed);
return;
}
if (!reason)
{
reason = "[no reason specified]";
}
if (!entity)
{
SetNote("error", "No entity found.");
Free(trimmed);
return;
}
Free(trimmed);
SetNote("info", "User sucessfully put into no-fly.");
ParseeGlobalBan(data, entity, reason);
}

View file

@ -9,9 +9,10 @@
#include <XMPPCommand.h>
#include <Parsee.h>
#include <XMPP.h>
#include <XML.h>
void
AdminsCallback(XMPPCommandManager *m, char *from, HashMap *form, XMLElement *out)
AdminsCallback(XMPPCommandManager *m, char *from, XMLElement *form, XMLElement *out)
{
ParseeData *data = XMPPGetManagerCookie(m);
char *trimmed = ParseeTrimJID(from);
@ -22,13 +23,7 @@ AdminsCallback(XMPPCommandManager *m, char *from, HashMap *form, XMLElement *out
if (!ParseeIsAdmin(data, trimmed))
{
XMLElement *note = XMLCreateTag("note");
XMLAddAttr(note, "type", "error");
txt = XMLCreateText("User is not authorised to execute command.");
XMLAddChild(note, txt);
XMLAddChild(out, note);
SetNote("error", "User is not authorised to execute command.");
Free(trimmed);
return;
}
@ -36,10 +31,8 @@ AdminsCallback(XMPPCommandManager *m, char *from, HashMap *form, XMLElement *out
x = XMLCreateTag("x");
title = XMLCreateTag("title");
{
XMLElement *title_text = XMLCreateText("Parsee administrators");
XMLAddChild(title, title_text);
}
SetTitle(x, "Parsee administrators");
XMLAddChild(x, title);
XMLAddAttr(x, "xmlns", "jabber:x:data");

View file

@ -9,11 +9,12 @@
#include <XMPPCommand.h>
#include <Parsee.h>
#include <XMPP.h>
#include <XML.h>
#define TITLE "Parsee global bans"
void
NoflyCallback(XMPPCommandManager *m, char *from, HashMap *form, XMLElement *out)
NoflyCallback(XMPPCommandManager *m, char *from, XMLElement *form, XMLElement *out)
{
ParseeData *data = XMPPGetManagerCookie(m);
char *trimmed = ParseeTrimJID(from);
@ -23,12 +24,7 @@ NoflyCallback(XMPPCommandManager *m, char *from, HashMap *form, XMLElement *out)
if (!ParseeIsAdmin(data, trimmed))
{
XMLElement *note = XMLCreateTag("note");
XMLAddAttr(note, "type", "error");
txt = XMLCreateText("User is not authorised to execute command.");
XMLAddChild(note, txt);
XMLAddChild(out, note);
SetNote("error", "User is not authorised to execute command.");
Free(trimmed);
return;
@ -41,10 +37,8 @@ NoflyCallback(XMPPCommandManager *m, char *from, HashMap *form, XMLElement *out)
XMLAddChild(out, x);
Free(trimmed);
{
XMLElement *title_text = XMLCreateText(TITLE);
XMLAddChild(title, title_text);
}
SetTitle(x, TITLE);
XMLAddAttr(x, "type", "result");
{

View file

@ -9,9 +9,10 @@
#include <XMPPCommand.h>
#include <Parsee.h>
#include <XMPP.h>
#include <XML.h>
void
StatusCallback(XMPPCommandManager *m, char *from, HashMap *form, XMLElement *out)
StatusCallback(XMPPCommandManager *m, char *from, XMLElement *form, XMLElement *out)
{
ParseeData *data = XMPPGetManagerCookie(m);
char *trimmed = ParseeTrimJID(from);
@ -26,12 +27,7 @@ StatusCallback(XMPPCommandManager *m, char *from, HashMap *form, XMLElement *out
if (!ParseeIsAdmin(data, trimmed))
{
XMLElement *note = XMLCreateTag("note");
XMLAddAttr(note, "type", "error");
txt = XMLCreateText("User is not authorised to execute command.");
XMLAddChild(note, txt);
XMLAddChild(out, note);
SetNote("error", "User is not authorised to execute command.");
Free(trimmed);
return;