mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 18:25:10 +00:00
[ADD/WIP] Start making a simple SAX parser, ASwerk
This commit is contained in:
parent
0fa95c2d14
commit
79217d3608
14 changed files with 1066 additions and 26 deletions
69
src/MatrixEventHandler.c
Normal file
69
src/MatrixEventHandler.c
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
#include <Parsee.h>
|
||||
|
||||
#include <Cytoplasm/Json.h>
|
||||
#include <Cytoplasm/Str.h>
|
||||
#include <Cytoplasm/Log.h>
|
||||
|
||||
#include <Matrix.h>
|
||||
#include <AS.h>
|
||||
|
||||
#define GrabString(obj, ...) JsonValueAsString(JsonGet(obj, __VA_ARGS__))
|
||||
static void
|
||||
ParseeMemberHandler(const ParseeConfig *conf, HashMap *event)
|
||||
{
|
||||
char *state_key = GrabString(event, 1, "state_key");
|
||||
char *membership = GrabString(event, 2, "content", "membership");
|
||||
char *room_id = GrabString(event, 1, "room_id");
|
||||
Log(LOG_INFO, "Membership '%s'->'%s'", state_key, membership);
|
||||
|
||||
if (StrEquals(membership, "invite") && ParseeIsPuppet(conf, state_key))
|
||||
{
|
||||
Log(LOG_INFO, "Looks like %s was invited to %s",
|
||||
state_key,
|
||||
GrabString(event, 1, "room_id")
|
||||
);
|
||||
ASJoin(conf, room_id, state_key);
|
||||
}
|
||||
}
|
||||
static void
|
||||
ParseeMessageHandler(const ParseeConfig *conf, HashMap *event)
|
||||
{
|
||||
char *msgtype = GrabString(event, 2, "content", "msgtype");
|
||||
char *body = GrabString(event, 2, "content", "body");
|
||||
char *id = GrabString(event, 1, "room_id");
|
||||
if (StrEquals(body, "!help"))
|
||||
{
|
||||
Log(LOG_ERR, "Not implemented!");
|
||||
ASSend(conf, id, NULL, "m.room.message",
|
||||
MatrixCreateNotice("No help, pal.")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ParseeEventHandler(const ParseeConfig *conf, HashMap *event)
|
||||
{
|
||||
char *event_type;
|
||||
if (!conf || !event)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Log(LOG_INFO, "Event by '%s', with type '%s'",
|
||||
JsonValueAsString(HashMapGet(event, "sender")),
|
||||
JsonValueAsString(HashMapGet(event, "type"))
|
||||
);
|
||||
|
||||
event_type = GrabString(event, 1, "type");
|
||||
if (StrEquals(event_type, "m.room.member"))
|
||||
{
|
||||
ParseeMemberHandler(conf, event);
|
||||
return;
|
||||
}
|
||||
if (StrEquals(event_type, "m.room.message"))
|
||||
{
|
||||
ParseeMessageHandler(conf, event);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue