[ADD/MOD] Help/stats and two-way modification

More on the Reverse Ideology!
This commit is contained in:
LDA 2024-06-29 19:10:28 +02:00
commit 8472ada953
13 changed files with 203 additions and 14 deletions

42
src/Commands/Help.c Normal file
View file

@ -0,0 +1,42 @@
#include <Routes.h>
#include <Cytoplasm/Cytoplasm.h>
#include <Cytoplasm/Memory.h>
#include <Cytoplasm/Str.h>
#include <Matrix.h>
#include <AS.h>
CommandHead(CmdHelp, cmd, argp)
{
ParseeCmdArg *args = argp;
ParseeData *data = args->data;
HashMap *json, *event = args->event;
char *profile = StrConcat(4,
"@", data->config->sender_localpart,
":", data->config->homeserver_host
);
char *id = GrabString(event, 1, "room_id");
char *msg;
Free(ASSend(
data->config, id, profile,
"m.room.message",
MatrixCreateNotice("Commands: ")
));
#define X_COMMAND(path, name, desc) { \
msg = StrConcat(3, path, "-", desc);\
Free(ASSend( \
data->config, id, profile, \
"m.room.message", \
MatrixCreateNotice(msg) \
)); \
Free(msg); \
} \
while (0);
COMMANDS
#undef X_COMMAND
Free(profile);
}

53
src/Commands/Stats.c Normal file
View file

@ -0,0 +1,53 @@
#include <Routes.h>
#include <Cytoplasm/Cytoplasm.h>
#include <Cytoplasm/Memory.h>
#include <Cytoplasm/Str.h>
#include <Matrix.h>
#include <AS.h>
CommandHead(CmdStats, cmd, argp)
{
ParseeCmdArg *args = argp;
ParseeData *data = args->data;
HashMap *json, *event = args->event;
char *profile = StrConcat(4,
"@", data->config->sender_localpart,
":", data->config->homeserver_host
);
char *id = GrabString(event, 1, "room_id");
char *msg;
size_t alloc = MemoryAllocated();
size_t kb = alloc >> 10;
size_t mb = kb >> 10;
size_t gb = mb >> 10;
size_t min = gb ? gb : (mb ? mb : (kb ? kb : alloc));
char *unit = gb ? "GB" : (mb ? "MB" : (kb ? "KB" : "B"));
char *l = StrInt(min);
msg = StrConcat(3,
"Information for " NAME " (",
CytoplasmGetVersionStr(), ")"
);
Free(ASSend(
data->config, id, profile,
"m.room.message",
MatrixCreateNotice(msg)
));
Free(msg);
msg = StrConcat(5,
"- Memory usage: ", l, " ", unit,
" (reported by Cytoplasm)"
);
Free(ASSend(
data->config, id, profile,
"m.room.message",
MatrixCreateNotice(msg)
));
Free(msg);
Free(l);
Free(profile);
}