2019-07-31 08:05:22 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <time.h>
|
2019-09-10 10:16:57 +00:00
|
|
|
#include <string.h>
|
2019-07-31 08:05:22 +00:00
|
|
|
|
2019-08-02 16:59:47 +00:00
|
|
|
#include "libnimbus.h"
|
2019-07-31 08:05:22 +00:00
|
|
|
|
|
|
|
void NimMain();
|
|
|
|
|
2019-10-30 11:18:11 +00:00
|
|
|
void print_msg(received_message* msg, void* udata) {
|
2019-09-10 10:16:57 +00:00
|
|
|
// Note: early null chars will terminate string early
|
|
|
|
printf("received message %.*s\n", (int)msg->decodedLen, msg->decoded);
|
2019-07-31 08:05:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* channel = "status-test-c";
|
|
|
|
|
|
|
|
const char* msg = "testing message";
|
|
|
|
|
|
|
|
int main(int argc, char* argv[]) {
|
|
|
|
time_t lastmsg;
|
|
|
|
|
|
|
|
NimMain();
|
2019-11-04 12:56:24 +00:00
|
|
|
nimbus_start(30303, false, false, 0.002);
|
2019-07-31 08:05:22 +00:00
|
|
|
|
2019-09-12 17:27:43 +00:00
|
|
|
nimbus_join_public_chat(channel, print_msg);
|
2019-07-31 08:05:22 +00:00
|
|
|
|
|
|
|
lastmsg = time(NULL);
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
usleep(1);
|
|
|
|
|
|
|
|
if (lastmsg + 1 <= time(NULL)) {
|
|
|
|
lastmsg = time(NULL);
|
|
|
|
char buf[4096];
|
|
|
|
snprintf(buf, 4095,
|
|
|
|
"[\"~#c4\",[\"%s\",\"text/plain\",\"~:public-group-user-message\",%ld,%ld,[\"^ \",\"~:chat-id\",\"%s\",\"~:text\",\"%s\"]]]",
|
|
|
|
msg, lastmsg * 1000 * 100, lastmsg * 1000, channel, msg);
|
|
|
|
|
|
|
|
printf("Posting %s\n", buf);
|
2019-09-12 17:27:43 +00:00
|
|
|
nimbus_post_public(channel, buf);
|
2019-07-31 08:05:22 +00:00
|
|
|
}
|
|
|
|
nimbus_poll();
|
|
|
|
}
|
|
|
|
}
|