summaryrefslogtreecommitdiffstats
path: root/src/main.c
blob: d658caa1142e6603a9505d9160b4a6ecdbc233e1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <libwebsockets.h>
#include <assert.h>
#include <signal.h>
#include <lib.c>
#include <ui.c>
#include <api.c>
void dc_signal (int i) {
	dc_interrupted++;
	return;
}
enum dc_status dc_print_message (struct dc_api_io o, void * n) {
	fprintf(stderr, "dc_print_message: %s#%s %s#%04d: %s\n", o.message->channel->guild->name,
			o.message->channel->name, o.message->user->username,
			o.message->user->discriminator, o.message->message);
	return DC_OK;
}
int main (int argc, char * argv[]) {
	if (DC_JSON_PATHS_LENGTH != sizeof(dc_json_paths)/sizeof(dc_json_paths[0]) || DC_JSON_PATHS_LENGTH > 255) {
		fprintf(stderr, "json paths enum: %d, array: %d (255 is max, must be same)\n", DC_JSON_PATHS_LENGTH, sizeof(dc_json_paths)/sizeof(dc_json_paths[0]));
		return 1;
	}
	struct dc_program * p = dc_program_init();
	struct dc_client * client = dc_client_init();
	lws_set_log_level(0xFF /* all message types */, NULL /* not change output location - cerr */);
	client->email = strdup(getenv("DC_E"));
	client->password = strdup(getenv("DC_P"));
	struct dc_api_io i = {
		.program = p,
		.type = DC_API_LOGIN,
		.client = client
	};
	dc_api_i(i);
	signal(SIGINT, dc_signal);
	i.type = DC_API_ATTACH;
	i.attached_function = dc_attached_function_init();
	i.attached_function->type = DC_API_MESSAGE;
	i.attached_function->function = dc_print_message;
	dc_api_i(i);
	while (!dc_interrupted)
		i = dc_api_o(i);
	/* dc_ui(argc, argv); */
	dc_program_free(p, DC_UNSET);
	return 0;
}