[FIX/WIP] Plumbing, -Werror, death to hitmen

Suspend killers are now no more. Except the actual killers to be gone
eventually.
Plumbing is also very basic as of now, but it "works".
This commit is contained in:
LDA 2024-07-05 20:24:15 +02:00
commit bb836789b2
23 changed files with 310 additions and 165 deletions

View file

@ -4,6 +4,7 @@
#include <Cytoplasm/Str.h>
#include <Matrix.h>
#include <Bot.h>
#include <AS.h>
CommandHead(CmdBanUser, cmd, argp)
@ -13,32 +14,21 @@ CommandHead(CmdBanUser, cmd, argp)
HashMap *event = args->event;
char *user = HashMapGet(cmd->arguments, "user");
char *room = HashMapGet(cmd->arguments, "room");
char *msg;
char *msgtype = GrabString(event, 2, "content", "msgtype");
char *body = GrabString(event, 2, "content", "body");
char *id = GrabString(event, 1, "room_id");
char *ev_id = GrabString(event, 1, "event_id");
char *sender = GrabString(event, 1, "sender");
char *profile = StrConcat(4,
"@", data->config->sender_localpart,
":", data->config->homeserver_host
);
BotInitialise();
if (!user || !room)
{
Free(profile);
BotDestroy();
return;
}
ASBan(data->config, room, user);
msg = StrConcat(3, "Banning '", user, "'...");
Free(ASSend(
data->config, id, profile,
"m.room.message",
MatrixCreateNotice(msg)
));
Free(msg);
Free(profile);
ReplySprintf("Banning %s from '%s'...",
user, room
);
BotDestroy();
}
CommandHead(CmdNoFlyList, cmd, argp)
{
@ -46,30 +36,19 @@ CommandHead(CmdNoFlyList, cmd, argp)
ParseeData *data = args->data;
HashMap *event = args->event;
char *user = HashMapGet(cmd->arguments, "user");
char *msg;
char *msgtype = GrabString(event, 2, "content", "msgtype");
char *body = GrabString(event, 2, "content", "body");
char *id = GrabString(event, 1, "room_id");
char *ev_id = GrabString(event, 1, "event_id");
char *sender = GrabString(event, 1, "sender");
char *profile = StrConcat(4,
"@", data->config->sender_localpart,
":", data->config->homeserver_host
);
char *reason = HashMapGet(cmd->arguments, "reason");
BotInitialise();
if (!user)
{
Free(profile);
BotDestroy();
return;
}
msg = StrConcat(3, "Banning '", user, "'...");
Free(ASSend(
data->config, id, profile,
"m.room.message",
MatrixCreateNotice(msg)
));
Free(msg);
ParseeGlobalBan(data, user);
Free(profile);
ReplySprintf("Banning %s for '%s'",
user, reason ? reason : "[no reason specified]"
);
ParseeGlobalBan(data, user, reason);
BotDestroy();
}

View file

@ -12,7 +12,7 @@ CommandHead(CmdHelp, cmd, argp)
{
ParseeCmdArg *args = argp;
ParseeData *data = args->data;
HashMap *json, *event = args->event;
HashMap *event = args->event;
BotInitialise();
ReplyBasic("Commands: ");

89
src/Commands/Plumb.c Normal file
View file

@ -0,0 +1,89 @@
#include <Routes.h>
#include <Cytoplasm/Memory.h>
#include <Cytoplasm/Str.h>
#include <Matrix.h>
#include <Bot.h>
#include <AS.h>
#include <stdlib.h>
CommandHead(CmdPlumb, cmd, argp)
{
ParseeCmdArg *args = argp;
ParseeData *data = args->data;
HashMap *event = args->event;
char *muc = NULL, *room = NULL, *chat_id = NULL;
char *room_id = NULL;
MUCInfo info = { .exists = false };
BotInitialise();
BotRequired(muc);
BotRequired(room);
/* Check MUC viability */
Log(LOG_INFO, "BAR1");
if (ParseeManageBan(args->data, muc, NULL))
{
ReplySprintf("MUC '%s' is not allowed on this bridge.", muc);
Log(LOG_INFO, "BAR1F");
goto end;
}
Log(LOG_INFO, "BAR2");
if (!XMPPQueryMUC(args->data->jabber, muc, &info))
{
ReplySprintf("MUC '%s' does not exist.", muc);
Log(LOG_INFO, "BAR2F");
goto end;
}
Log(LOG_INFO, "BAR3");
if ((chat_id = ParseeGetFromMUCID(args->data, muc)))
{
Free(chat_id);
chat_id = NULL;
ReplySprintf("MUC '%s' is already mapped.", muc);
Log(LOG_INFO, "BAR3F");
goto end;
}
Log(LOG_INFO, "FOO");
/* Check room viability */
room_id = ASJoin(args->data->config, room, NULL);
if (!room_id)
{
ReplySprintf("Room '%s' does not exist.", room);
Log(LOG_INFO, "FOO2");
goto end;
}
Log(LOG_INFO, "FOO3");
if ((chat_id = ParseeGetFromRoomID(args->data, room_id)))
{
Free(chat_id);
chat_id = NULL;
ReplySprintf("Room '%s' is already mapped.", room);
Log(LOG_INFO, "FOO4");
goto end;
}
Log(LOG_INFO, "FOO5");
chat_id = ParseePushMUC(args->data, room_id, muc);
if (chat_id)
{
char *rev = StrConcat(2, muc, "/parsee");
XMPPJoinMUC(args->data->jabber, "parsee", rev);
Free(rev);
}
Log(LOG_INFO, "FOO6");
ReplySprintf("Plumbed '%s'", muc);
end:
Log(LOG_INFO, "End.");
BotDestroy();
Free(chat_id);
Free(room_id);
XMPPFreeMUCInfo(info);
}

View file

@ -12,8 +12,7 @@ CommandHead(CmdStats, cmd, argp)
{
ParseeCmdArg *args = argp;
ParseeData *data = args->data;
HashMap *json, *event = args->event;
char *msg;
HashMap *event = args->event;
size_t alloc = MemoryAllocated();
size_t kb = alloc >> 10;
size_t mb = kb >> 10;
@ -30,7 +29,7 @@ CommandHead(CmdStats, cmd, argp)
);
ReplySprintf("- Memory used: %d%s (reported by Cytoplasm)",
min, unit
(int) min, unit
);
ReplySprintf("- Source code and licensing information: %s",
REPOSITORY

View file

@ -16,7 +16,6 @@ CommandHead(CmdUnlinkMUC, cmd, argp)
HashMap *json, *event = args->event, *mucs;
DbRef *ref;
char *muc = NULL, *chat_id = NULL, *room = NULL;
JsonValue *val;
BotInitialise();