Parsee/src/include/Bot.h
LDA dd180ee3f4 [MOD] Use server_base instead of the API host
This wasn't an issue because the server I test on has the same API host
as its name.
2024-07-26 17:13:02 +02:00

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