mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 19:55:10 +00:00
I honestly don't know what to call it.
It's not a 0.2 release, btw.
This commit is contained in:
parent
e7ba1fa48d
commit
3ceae7b053
13 changed files with 179 additions and 85 deletions
|
|
@ -25,7 +25,7 @@ CommandParse(char *cmd)
|
|||
}
|
||||
|
||||
end_data = strchr(cmd, ' ');
|
||||
if (!end_data)
|
||||
if (!end_data || (cmd > end_data))
|
||||
{
|
||||
ret = Malloc(sizeof(*ret));
|
||||
ret->command = StrDuplicate(cmd);
|
||||
|
|
|
|||
|
|
@ -22,11 +22,9 @@ CommandHead(CmdBanUser, cmd, argp)
|
|||
BotDestroy();
|
||||
return;
|
||||
}
|
||||
ASBan(data->config, room, user);
|
||||
|
||||
ReplySprintf("Banning %s from '%s'...",
|
||||
user, room
|
||||
);
|
||||
ASBan(data->config, room, user);
|
||||
ReplySprintf("Banning %s from '%s'...", user, room);
|
||||
|
||||
BotDestroy();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,43 +9,60 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
|
||||
static bool
|
||||
Grab(ParseeData *data, Command *cmd, char **muc, char **chat_id, char **room)
|
||||
{
|
||||
if (HashMapGet(cmd->arguments, "muc"))
|
||||
{
|
||||
*muc = HashMapGet(cmd->arguments, "muc");
|
||||
|
||||
*chat_id = ParseeGetFromMUCID(data, *muc);
|
||||
*room = ParseeGetRoomID(data, *chat_id);
|
||||
if (!chat_id || !room)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if (HashMapGet(cmd->arguments, "room"))
|
||||
{
|
||||
*room = HashMapGet(cmd->arguments, "room");
|
||||
|
||||
*chat_id = ParseeGetFromRoomID(data, *room);
|
||||
*muc = ParseeGetMUCID(data, *chat_id);
|
||||
if (!chat_id || !muc)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
CommandHead(CmdUnlinkMUC, cmd, argp)
|
||||
{
|
||||
ParseeCmdArg *args = argp;
|
||||
ParseeData *data = args->data;
|
||||
HashMap *json, *event = args->event, *mucs;
|
||||
DbRef *ref;
|
||||
char *muc = NULL, *chat_id = NULL, *room = NULL;
|
||||
|
||||
BotInitialise();
|
||||
|
||||
muc = HashMapGet(cmd->arguments, "muc");
|
||||
if (!muc)
|
||||
if (!Grab(data, cmd, &muc, &chat_id, &room))
|
||||
{
|
||||
ReplyBasic("`muc` field REQUIRED.");
|
||||
ReplyBasic("`muc`|`room` REQUIRED");
|
||||
goto end;
|
||||
}
|
||||
|
||||
ref = DbLock(data->db, 1, "chats");
|
||||
json = DbJson(ref);
|
||||
chat_id = StrDuplicate(GrabString(json, 2, "mucs", muc));
|
||||
chat_id = ParseeGetFromMUCID(data, muc);
|
||||
room = ParseeGetRoomID(data, chat_id);
|
||||
if (!chat_id)
|
||||
{
|
||||
ReplySprintf("No internal mapping to '%s'.", muc);
|
||||
goto end;
|
||||
}
|
||||
mucs = GrabObject(json, 1, "mucs");
|
||||
JsonValueFree(HashMapDelete(mucs, muc));
|
||||
DbUnlock(data->db, ref);
|
||||
|
||||
room = ParseeGetRoomID(data, chat_id);
|
||||
ref = DbLock(data->db, 1, "chats");
|
||||
json = DbJson(ref);
|
||||
mucs = GrabObject(json, 1, "rooms");
|
||||
JsonValueFree(HashMapDelete(mucs, room));
|
||||
DbUnlock(data->db, ref);
|
||||
|
||||
DbDelete(data->db, 2, "chats", chat_id);
|
||||
ParseeUnlinkRoom(data, chat_id);
|
||||
|
||||
/* TODO: Do it automatically, if *not plumbed* */
|
||||
ReplySprintf("The MUC %s is now *unlinked*.", muc);
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ static const Argument arguments[] =
|
|||
"Generates a parsee.yaml AS file before exiting")
|
||||
Arg('v', false, NULL,
|
||||
"Forces Parsee to print in a more verbose fashion "
|
||||
"(-vv prints stanzas to stderr)")
|
||||
"(-vvv prints stanzas to stderr)")
|
||||
Arg('h', false, NULL,
|
||||
"Generates an help screen(this one!)")
|
||||
|
||||
|
|
@ -116,6 +116,9 @@ Main(Array *args, HashMap *env)
|
|||
case PARSEE_VERBOSE_LOG:
|
||||
LogConfigLevelSet(LogConfigGlobal(), LOG_DEBUG);
|
||||
break;
|
||||
case PARSEE_VERBOSE_TIMINGS:
|
||||
Log(LOG_DEBUG, "Logging bench information.");
|
||||
break;
|
||||
case PARSEE_VERBOSE_STANZA:
|
||||
Log(LOG_DEBUG, "Enabling stanza printing.");
|
||||
break;
|
||||
|
|
@ -226,6 +229,8 @@ Main(Array *args, HashMap *env)
|
|||
if (ASRegisterUser(parsee_conf, parsee_conf->sender_localpart))
|
||||
{
|
||||
char *parsee = ParseeMXID(conf.handlerArgs);
|
||||
|
||||
/* TODO: An hardcoded avatar like this sucks. */
|
||||
ASSetAvatar(parsee_conf,
|
||||
parsee,
|
||||
"mxc://tedomum.net/"
|
||||
|
|
|
|||
|
|
@ -1,39 +0,0 @@
|
|||
#include <Parsee.h>
|
||||
|
||||
#include <Cytoplasm/Memory.h>
|
||||
#include <Cytoplasm/Json.h>
|
||||
|
||||
void
|
||||
ParseeUnlinkRoom(ParseeData *data, char *chat_id)
|
||||
{
|
||||
char *muc, *room;
|
||||
DbRef *ref;
|
||||
if (!data || !chat_id)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
muc = ParseeGetMUCID(data, chat_id);
|
||||
room = ParseeGetRoomID(data, chat_id);
|
||||
if (!muc || !room)
|
||||
{
|
||||
Free(muc);
|
||||
Free(room);
|
||||
return;
|
||||
}
|
||||
|
||||
ref = DbLock(data->db, 1, "chats");
|
||||
JsonValueFree(HashMapDelete(
|
||||
GrabObject(DbJson(ref), 1, "rooms"),
|
||||
room
|
||||
));
|
||||
JsonValueFree(HashMapDelete(
|
||||
GrabObject(DbJson(ref), 1, "mucs"),
|
||||
muc
|
||||
));
|
||||
DbUnlock(data->db, ref);
|
||||
DbDelete(data->db, 2, "chats", chat_id);
|
||||
|
||||
Free(muc);
|
||||
Free(room);
|
||||
}
|
||||
|
|
@ -538,3 +538,38 @@ end:
|
|||
return ret;
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
ParseeUnlinkRoom(ParseeData *data, char *chat_id)
|
||||
{
|
||||
char *muc, *room;
|
||||
DbRef *ref;
|
||||
if (!data || !chat_id)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
muc = ParseeGetMUCID(data, chat_id);
|
||||
room = ParseeGetRoomID(data, chat_id);
|
||||
if (!muc || !room)
|
||||
{
|
||||
Free(muc);
|
||||
Free(room);
|
||||
return;
|
||||
}
|
||||
|
||||
ref = DbLock(data->db, 1, "chats");
|
||||
JsonValueFree(HashMapDelete(
|
||||
GrabObject(DbJson(ref), 1, "rooms"),
|
||||
room
|
||||
));
|
||||
JsonValueFree(HashMapDelete(
|
||||
GrabObject(DbJson(ref), 1, "mucs"),
|
||||
muc
|
||||
));
|
||||
DbUnlock(data->db, ref);
|
||||
DbDelete(data->db, 2, "chats", chat_id);
|
||||
|
||||
Free(muc);
|
||||
Free(room);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -223,7 +223,10 @@ MessageStanza(ParseeData *args, XMLElement *stanza, XMPPThread *thr)
|
|||
ParseePushOIDTable(from, occ_id);
|
||||
}
|
||||
}
|
||||
Log(LOG_DEBUG, "XEP-421: %fs", Elapsed(rectime));
|
||||
if (args->verbosity >= PARSEE_VERBOSE_TIMINGS)
|
||||
{
|
||||
Log(LOG_DEBUG, "XEP-421: %fs", Elapsed(rectime));
|
||||
}
|
||||
|
||||
if (StrEquals(type, "error"))
|
||||
{
|
||||
|
|
@ -268,7 +271,10 @@ end_error:
|
|||
);
|
||||
return false;
|
||||
}
|
||||
Log(LOG_DEBUG, "Error management: %fs", Elapsed(rectime));
|
||||
if (args->verbosity >= PARSEE_VERBOSE_TIMINGS)
|
||||
{
|
||||
Log(LOG_DEBUG, "Error management: %fs", Elapsed(rectime));
|
||||
}
|
||||
|
||||
if (moderated)
|
||||
{
|
||||
|
|
@ -296,19 +302,28 @@ end_error:
|
|||
body = XMLookForUnique(stanza, "body");
|
||||
|
||||
PEPManagerHandle(thr->info->pep_manager, stanza);
|
||||
Log(LOG_DEBUG, "PEP management: %fs", Elapsed(rectime));
|
||||
if (args->verbosity >= PARSEE_VERBOSE_TIMINGS)
|
||||
{
|
||||
Log(LOG_DEBUG, "PEP management: %fs", Elapsed(rectime));
|
||||
}
|
||||
|
||||
to = ParseeDecodeMXID(HashMapGet(stanza->attrs, "to"));
|
||||
decode_from = ParseeLookupJID(from);
|
||||
from_matrix = ParseeEncodeJID(args->config, decode_from, true);
|
||||
room = ParseeFindDMRoom(args, to, from);
|
||||
data = body ? ArrayGet(body->children, 0) : NULL;
|
||||
Log(LOG_DEBUG, "Fetching user info: %fs", Elapsed(rectime));
|
||||
if (args->verbosity >= PARSEE_VERBOSE_TIMINGS)
|
||||
{
|
||||
Log(LOG_DEBUG, "Fetching user info: %fs", Elapsed(rectime));
|
||||
}
|
||||
|
||||
/* TODO: CLEAN THAT UP INTO A CREATEDM FUNCTION */
|
||||
mroom_id = ParseeGetBridgedRoom(args, stanza);
|
||||
Log(LOG_DEBUG, "Bridging event to '%s'...", mroom_id);
|
||||
Log(LOG_DEBUG, "Fetching bridge: %fs", Elapsed(rectime));
|
||||
if (args->verbosity >= PARSEE_VERBOSE_TIMINGS)
|
||||
{
|
||||
Log(LOG_DEBUG, "Fetching bridge: %fs", Elapsed(rectime));
|
||||
}
|
||||
if (!mroom_id && !room && !XMPPIsParseeStanza(stanza) &&
|
||||
to && *to == '@')
|
||||
{
|
||||
|
|
@ -367,7 +382,10 @@ end_error:
|
|||
StreamFlush(jabber->stream);
|
||||
pthread_mutex_unlock(&jabber->write_lock);
|
||||
XMLFreeElement(ps);
|
||||
Log(LOG_DEBUG, "Subscription to XEP-0084: %fs", Elapsed(rectime));
|
||||
if (args->verbosity >= PARSEE_VERBOSE_TIMINGS)
|
||||
{
|
||||
Log(LOG_DEBUG, "Subscription to XEP-0084: %fs", Elapsed(rectime));
|
||||
}
|
||||
|
||||
Free(parsee);
|
||||
Free(trim);
|
||||
|
|
@ -380,7 +398,10 @@ end_error:
|
|||
pthread_mutex_unlock(&thr->info->chk_lock);
|
||||
|
||||
LazyRegister(args, encoded, !chat ? res : NULL);
|
||||
Log(LOG_DEBUG, "Matrix registration: %fs", Elapsed(rectime));
|
||||
if (args->verbosity >= PARSEE_VERBOSE_TIMINGS)
|
||||
{
|
||||
Log(LOG_DEBUG, "Matrix registration: %fs", Elapsed(rectime));
|
||||
}
|
||||
|
||||
reactions = XMLookForTKV(stanza,
|
||||
"reactions", "xmlns", "urn:xmpp:reactions:0"
|
||||
|
|
@ -539,7 +560,10 @@ end_error:
|
|||
}
|
||||
|
||||
ProcessChatstates(args, stanza);
|
||||
Log(LOG_DEBUG, "Chatstate management: %fs", Elapsed(rectime));
|
||||
if (args->verbosity >= PARSEE_VERBOSE_TIMINGS)
|
||||
{
|
||||
Log(LOG_DEBUG, "Chatstate management: %fs", Elapsed(rectime));
|
||||
}
|
||||
|
||||
end:
|
||||
Free(mroom_id);
|
||||
|
|
|
|||
|
|
@ -20,7 +20,8 @@ typedef struct ParseeData ParseeData;
|
|||
|
||||
#define PARSEE_VERBOSE_NONE 0
|
||||
#define PARSEE_VERBOSE_LOG 1
|
||||
#define PARSEE_VERBOSE_STANZA 2
|
||||
#define PARSEE_VERBOSE_TIMINGS 2
|
||||
#define PARSEE_VERBOSE_STANZA 3
|
||||
#define PARSEE_VERBOSE_COMICAL 53 /* MINUTES */
|
||||
|
||||
typedef struct ParseeConfig {
|
||||
|
|
@ -100,7 +101,8 @@ typedef struct Argument {
|
|||
/* A base64-encoded Parsee logo */
|
||||
extern const char media_parsee_logo[];
|
||||
|
||||
/* An ASCII-art rendition of "小橋" */
|
||||
/* An ASCII-art rendition of "小橋".
|
||||
* I'm sorry for its quality. If anyone wants to redraw it, feel free. */
|
||||
#define PARSEE_ASCII_LINES 8
|
||||
extern const char *parsee_ascii[PARSEE_ASCII_LINES];
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue