[ADD/WIP] No-fly list for Matrix users

Imagine being in Parsee jail.
This commit is contained in:
LDA 2024-06-28 20:27:35 +02:00
commit f434f7aa87
4 changed files with 120 additions and 20 deletions

View file

@ -105,6 +105,8 @@ ParseeBotHandler(ParseeData *data, HashMap *event)
}
body++;
#define BAN_USER "ban-user "
#define BAN_LIST "ban-list "
#define LS_USERS "ls-flying"
if (!strncmp(body, BAN_USER, strlen(BAN_USER)))
{
char user[256] = { 0 };
@ -126,6 +128,54 @@ ParseeBotHandler(ParseeData *data, HashMap *event)
));
Free(msg);
}
else if (!strncmp(body, LS_USERS, strlen(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 (!strncmp(body, BAN_LIST, strlen(BAN_LIST)))
{
char user[256] = { 0 };
char *msg;
body += strlen(BAN_USER);
if (sscanf(body, "%255s", &user) != 1)
{
goto end;
}
msg = StrConcat(3, "Banning '", user, "'...");
Free(ASSend(
data->config, id, profile,
"m.room.message",
MatrixCreateNotice(msg)
));
Free(msg);
ParseeGlobalBan(data, user);
}
end:
Free(profile);
}
@ -155,7 +205,8 @@ ParseeMessageHandler(ParseeData *data, HashMap *event)
direct = JsonValueAsBoolean(HashMapGet(json, "is_direct"));
DbUnlock(data->db, ref);
if (ParseeIsPuppet(data->config, sender))
if (ParseeIsPuppet(data->config, sender) ||
ParseeManageBan(data, sender, id))
{
Free(chat_id);
Free(reply_id);