mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-14 01:55:16 +00:00
[MOD/WIP] Threading, and bot "API".
Sloppy code!
This commit is contained in:
parent
5f2c3a9cb8
commit
b81e267141
8 changed files with 259 additions and 124 deletions
|
|
@ -5,6 +5,7 @@
|
|||
#include <Cytoplasm/Str.h>
|
||||
|
||||
#include <Matrix.h>
|
||||
#include <Bot.h>
|
||||
#include <AS.h>
|
||||
|
||||
CommandHead(CmdHelp, cmd, argp)
|
||||
|
|
@ -12,31 +13,16 @@ 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;
|
||||
BotInitialise();
|
||||
|
||||
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);
|
||||
ReplyBasic("Commands: ");
|
||||
#define X_COMMAND(path, name, desc) ReplySprintf("- %s: %s", path, desc);
|
||||
COMMANDS
|
||||
#undef X_COMMAND
|
||||
|
||||
Free(profile);
|
||||
ReplySprintf("- Source code and licensing information: %s",
|
||||
REPOSITORY
|
||||
);
|
||||
ReplyBasic("*Written with a shoelace and UHU glue by LDA <3 !*");
|
||||
BotDestroy();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#include <Cytoplasm/Str.h>
|
||||
|
||||
#include <Matrix.h>
|
||||
#include <Bot.h>
|
||||
#include <AS.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
|
@ -14,36 +15,21 @@ CommandHead(CmdListBans, cmd, 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");
|
||||
char *banned;
|
||||
JsonValue *val;
|
||||
|
||||
BotInitialise();
|
||||
|
||||
listed = DbLock(data->db, 1, "global_bans");
|
||||
json = DbJson(listed);
|
||||
|
||||
ReplyBasic("Users on the no-fly list:");
|
||||
while (HashMapIterate(json, &banned, (void **) &val))
|
||||
{
|
||||
tmp = str;
|
||||
str = StrConcat(4, str, "- ", banned, "\n");
|
||||
Free(tmp);
|
||||
/* TODO: Add no-fly reasons */
|
||||
ReplySprintf("- %s", banned);
|
||||
}
|
||||
|
||||
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);
|
||||
BotDestroy();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include <Cytoplasm/Str.h>
|
||||
|
||||
#include <Matrix.h>
|
||||
#include <Bot.h>
|
||||
#include <AS.h>
|
||||
|
||||
CommandHead(CmdStats, cmd, argp)
|
||||
|
|
@ -12,11 +13,6 @@ 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;
|
||||
|
|
@ -24,30 +20,22 @@ CommandHead(CmdStats, cmd, argp)
|
|||
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(), ")"
|
||||
BotInitialise();
|
||||
|
||||
|
||||
/* TODO: Separate these into different "categories" */
|
||||
ReplySprintf("Information for %s v%s (Cytoplasm %s)",
|
||||
NAME, VERSION, CytoplasmGetVersionStr()
|
||||
);
|
||||
Free(ASSend(
|
||||
data->config, id, profile,
|
||||
"m.room.message",
|
||||
MatrixCreateNotice(msg)
|
||||
));
|
||||
Free(msg);
|
||||
|
||||
msg = StrConcat(5,
|
||||
"- Memory usage: ", l, " ", unit,
|
||||
" (reported by Cytoplasm)"
|
||||
ReplySprintf("- Memory used: %d%s (reported by Cytoplasm)",
|
||||
min, unit
|
||||
);
|
||||
Free(ASSend(
|
||||
data->config, id, profile,
|
||||
"m.room.message",
|
||||
MatrixCreateNotice(msg)
|
||||
));
|
||||
Free(msg);
|
||||
Free(l);
|
||||
ReplySprintf("- Source code and licensing information: %s",
|
||||
REPOSITORY
|
||||
);
|
||||
ReplyBasic("*Written with a shoelace and UHU glue by LDA <3 !*");
|
||||
|
||||
Free(profile);
|
||||
BotDestroy();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue