mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 21:25:11 +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
|
|
@ -10,7 +10,6 @@
|
|||
#include <Matrix.h>
|
||||
#include <AS.h>
|
||||
|
||||
#define GrabString(obj, ...) JsonValueAsString(JsonGet(obj, __VA_ARGS__))
|
||||
static void
|
||||
ParseeMemberHandler(ParseeData *data, HashMap *event)
|
||||
{
|
||||
|
|
@ -106,95 +105,15 @@ ParseeBotHandler(ParseeData *data, HashMap *event)
|
|||
return;
|
||||
}
|
||||
body++;
|
||||
#define BAN_USER "ban-user"
|
||||
#define BAN_LIST "ban-list"
|
||||
#define LS_USERS "ls-flying"
|
||||
|
||||
cmd = CommandParse(body);
|
||||
if (cmd && StrEquals(cmd->command, BAN_USER))
|
||||
{
|
||||
char *user = HashMapGet(cmd->arguments, "user");
|
||||
char *room = HashMapGet(cmd->arguments, "room");
|
||||
char *msg;
|
||||
ParseeCmdArg arg;
|
||||
arg.data = data;
|
||||
arg.event = event;
|
||||
|
||||
if (!user || !room)
|
||||
{
|
||||
goto end;
|
||||
}
|
||||
ASBan(data->config, room, user);
|
||||
|
||||
msg = StrConcat(3, "Banning '", user, "'...");
|
||||
Free(ASSend(
|
||||
data->config, id, profile,
|
||||
"m.room.message",
|
||||
MatrixCreateNotice(msg)
|
||||
));
|
||||
Free(msg);
|
||||
}
|
||||
else if (cmd && StrEquals(cmd->command, "set-pl"))
|
||||
{
|
||||
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)
|
||||
{
|
||||
goto end;
|
||||
}
|
||||
map = ASGetPL(data->config, room);
|
||||
JsonValueFree(JsonSet(
|
||||
map, JsonValueInteger(pl),
|
||||
2, "users", user
|
||||
));
|
||||
ASSetPL(data->config, room, map);
|
||||
}
|
||||
else if (cmd && StrEquals(cmd->command, LS_USERS))
|
||||
{
|
||||
DbRef *listed = DbLock(data->db, 1, "global_bans");
|
||||
HashMap *json = DbJson(listed);
|
||||
char *str = NULL, *tmp = NULL, *banned;
|
||||
JsonValue *val;
|
||||
|
||||
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);
|
||||
}
|
||||
else if (cmd && StrEquals(cmd->command, BAN_LIST))
|
||||
{
|
||||
char *user = HashMapGet(cmd->arguments, "user");
|
||||
char *msg;
|
||||
|
||||
if (!user)
|
||||
{
|
||||
goto end;
|
||||
}
|
||||
|
||||
msg = StrConcat(3, "Banning '", user, "'...");
|
||||
Free(ASSend(
|
||||
data->config, id, profile,
|
||||
"m.room.message",
|
||||
MatrixCreateNotice(msg)
|
||||
));
|
||||
Free(msg);
|
||||
ParseeGlobalBan(data, user);
|
||||
Log(LOG_INFO, "Routing...");
|
||||
RouteCommand(data->handler, cmd, &arg);
|
||||
}
|
||||
end:
|
||||
Free(profile);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue