mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 21:25:11 +00:00
54 lines
2.1 KiB
C
54 lines
2.1 KiB
C
#ifndef PARSEE_BOT_H
|
|
#define PARSEE_BOT_H
|
|
|
|
#include <Cytoplasm/HashMap.h>
|
|
#include <Cytoplasm/Memory.h>
|
|
#include <Cytoplasm/Log.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <Parsee.h>
|
|
|
|
#define BotInitialise() char *profile = ParseeMXID(data); \
|
|
char *id = GrabString(event, 1, "room_id")
|
|
|
|
#define BotRequired(prop) prop = HashMapGet(cmd->arguments, #prop); \
|
|
if (!prop) \
|
|
{ \
|
|
ReplyBasic("Field `" #prop "` REQUIRED."); \
|
|
goto end; \
|
|
}
|
|
|
|
#define BotDestroy() Free(profile)
|
|
|
|
#define ReplyBasic(rep) do \
|
|
{ \
|
|
Free(ASSend( \
|
|
data->config, id, profile, \
|
|
"m.room.message", \
|
|
MatrixCreateNotice(rep) \
|
|
)); \
|
|
} \
|
|
while(0)
|
|
|
|
#define ReplySprintf(fp,...) do \
|
|
{ \
|
|
char *formatted = NULL; \
|
|
size_t fmt_len = 0; \
|
|
fmt_len = snprintf( \
|
|
NULL, 0, fp, __VA_ARGS__ \
|
|
); \
|
|
formatted = Malloc(fmt_len + 2); \
|
|
snprintf( \
|
|
formatted, fmt_len + 1, fp, __VA_ARGS__ \
|
|
); \
|
|
Free(ASSend( \
|
|
data->config, id, profile, \
|
|
"m.room.message", \
|
|
MatrixCreateNotice(formatted) \
|
|
)); \
|
|
Free(formatted); \
|
|
} \
|
|
while(0)
|
|
|
|
#endif
|