mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-14 02:05:17 +00:00
[MOD/WIP] Use actual router
This commit is contained in:
parent
307fe6a341
commit
0ee79cc586
7 changed files with 183 additions and 87 deletions
75
src/Commands/BanUser.c
Normal file
75
src/Commands/BanUser.c
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
#include <Routes.h>
|
||||
|
||||
#include <Cytoplasm/Memory.h>
|
||||
#include <Cytoplasm/Str.h>
|
||||
|
||||
#include <Matrix.h>
|
||||
#include <AS.h>
|
||||
|
||||
CommandHead(CmdBanUser, cmd, argp)
|
||||
{
|
||||
ParseeCmdArg *args = argp;
|
||||
ParseeData *data = args->data;
|
||||
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
|
||||
);
|
||||
|
||||
if (!user || !room)
|
||||
{
|
||||
Free(profile);
|
||||
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);
|
||||
}
|
||||
CommandHead(CmdNoFlyList, cmd, argp)
|
||||
{
|
||||
ParseeCmdArg *args = 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
|
||||
);
|
||||
|
||||
if (!user)
|
||||
{
|
||||
Free(profile);
|
||||
return;
|
||||
}
|
||||
|
||||
msg = StrConcat(3, "Banning '", user, "'...");
|
||||
Free(ASSend(
|
||||
data->config, id, profile,
|
||||
"m.room.message",
|
||||
MatrixCreateNotice(msg)
|
||||
));
|
||||
Free(msg);
|
||||
ParseeGlobalBan(data, user);
|
||||
Free(profile);
|
||||
}
|
||||
49
src/Commands/ListBans.c
Normal file
49
src/Commands/ListBans.c
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
#include <Routes.h>
|
||||
|
||||
#include <Cytoplasm/Memory.h>
|
||||
#include <Cytoplasm/Str.h>
|
||||
|
||||
#include <Matrix.h>
|
||||
#include <AS.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
CommandHead(CmdListBans, cmd, argp)
|
||||
{
|
||||
ParseeCmdArg *args = argp;
|
||||
ParseeData *data = args->data;
|
||||
HashMap *json, *event = args->event;
|
||||
DbRef *listed;
|
||||
char *str = NULL, *tmp = NULL, *banned;
|
||||
char *profile = StrConcat(4,
|
||||
"@", data->config->sender_localpart,
|
||||
":", data->config->homeserver_host
|
||||
);
|
||||
char *id = GrabString(event, 1, "room_id");
|
||||
JsonValue *val;
|
||||
|
||||
listed = DbLock(data->db, 1, "global_bans");
|
||||
json = DbJson(listed);
|
||||
|
||||
while (HashMapIterate(json, &banned, (void **) &val))
|
||||
{
|
||||
tmp = str;
|
||||
str = StrConcat(4, str, "- ", banned, "\n");
|
||||
Free(tmp);
|
||||
}
|
||||
|
||||
Free(ASSend(
|
||||
data->config, id, profile,
|
||||
"m.room.message",
|
||||
MatrixCreateNotice("No-fly listed users:")
|
||||
));
|
||||
Free(ASSend(
|
||||
data->config, id, profile,
|
||||
"m.room.message",
|
||||
MatrixCreateNotice(str)
|
||||
));
|
||||
|
||||
Free(str);
|
||||
DbUnlock(data->db, listed);
|
||||
Free(profile);
|
||||
}
|
||||
28
src/Commands/SetPL.c
Normal file
28
src/Commands/SetPL.c
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#include <Routes.h>
|
||||
|
||||
#include <AS.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
CommandHead(CmdSetPL, cmd, argp)
|
||||
{
|
||||
ParseeCmdArg *args = argp;
|
||||
ParseeData *data = args->data;
|
||||
char *user = HashMapGet(cmd->arguments, "user");
|
||||
char *room = HashMapGet(cmd->arguments, "room");
|
||||
char *pl_str = HashMapGet(cmd->arguments, "pl");
|
||||
long pl = strtol(pl_str, NULL, 10);
|
||||
HashMap *map;
|
||||
|
||||
|
||||
if (!user || !pl_str)
|
||||
{
|
||||
return;
|
||||
}
|
||||
map = ASGetPL(data->config, room);
|
||||
JsonValueFree(JsonSet(
|
||||
map, JsonValueInteger(pl),
|
||||
2, "users", user
|
||||
));
|
||||
ASSetPL(data->config, room, map);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue