[ADD] Be able to set the power level of an admin

Taking over users!
This commit is contained in:
LDA 2024-06-28 23:58:23 +02:00
commit 307fe6a341
3 changed files with 69 additions and 1 deletions

View file

@ -422,6 +422,50 @@ ASGetName(const ParseeConfig *c, char *room, char *user)
} }
return ret; return ret;
} }
HashMap *
ASGetPL(const ParseeConfig *c, char *room)
{
char *path;
HttpClientContext *ctx;
HashMap *reply;
if (!c || !room)
{
return NULL;
}
room = HttpUrlEncode(room);
path = StrConcat(4,
"/_matrix/client/v3/rooms/", room,
"/state/m.room.power_levels/", ""
);
ctx = ParseeCreateRequest(c, HTTP_GET, path);
Free(room);
ASAuthenticateRequest(c, ctx);
HttpRequestSendHeaders(ctx);
HttpRequestSend(ctx);
reply = JsonDecode(HttpClientStream(ctx));
HttpClientContextFree(ctx);
Free(path);
return reply;
}
void
ASSetPL(const ParseeConfig *conf, char *id, HashMap *m)
{
char *user;
if (!conf || !id || !m)
{
return;
}
user = StrConcat(4,
"@",conf->sender_localpart,
":",conf->homeserver_host
);
ASSetState(conf, id, "m.room.power_levels", "", user, m);
Free(user);
}
char * char *
ASUpload(const ParseeConfig *c, Stream *from, unsigned int size) ASUpload(const ParseeConfig *c, Stream *from, unsigned int size)
{ {

View file

@ -5,6 +5,7 @@
#include <Cytoplasm/Str.h> #include <Cytoplasm/Str.h>
#include <Cytoplasm/Log.h> #include <Cytoplasm/Log.h>
#include <string.h> #include <string.h>
#include <stdlib.h>
#include <Matrix.h> #include <Matrix.h>
#include <AS.h> #include <AS.h>
@ -112,7 +113,7 @@ ParseeBotHandler(ParseeData *data, HashMap *event)
if (cmd && StrEquals(cmd->command, BAN_USER)) if (cmd && StrEquals(cmd->command, BAN_USER))
{ {
char *user = HashMapGet(cmd->arguments, "user"); char *user = HashMapGet(cmd->arguments, "user");
char *room = HashMapGet(cmd->arguments, "user"); char *room = HashMapGet(cmd->arguments, "room");
char *msg; char *msg;
if (!user || !room) if (!user || !room)
@ -129,6 +130,25 @@ ParseeBotHandler(ParseeData *data, HashMap *event)
)); ));
Free(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)) else if (cmd && StrEquals(cmd->command, LS_USERS))
{ {
DbRef *listed = DbLock(data->db, 1, "global_bans"); DbRef *listed = DbLock(data->db, 1, "global_bans");

View file

@ -39,6 +39,10 @@ extern char * ASSend(const ParseeConfig *, char *, char *, char *, HashMap *);
/* Sets a state event with a specific type and body */ /* Sets a state event with a specific type and body */
extern void ASSetState(const ParseeConfig *conf, char *id, char *type, char *key, char *mask, HashMap *event); extern void ASSetState(const ParseeConfig *conf, char *id, char *type, char *key, char *mask, HashMap *event);
/* Gets/Sets the content for a PL event */
extern HashMap *ASGetPL(const ParseeConfig *conf, char *id);
extern void ASSetPL(const ParseeConfig *conf, char *id, HashMap *m);
/* Creates a room, with a masquerade user as its creator. This function /* Creates a room, with a masquerade user as its creator. This function
* returns it's ID if it exists. */ * returns it's ID if it exists. */
extern char * ASCreateRoom(const ParseeConfig *c, char *by, char *alias); extern char * ASCreateRoom(const ParseeConfig *c, char *by, char *alias);