summaryrefslogtreecommitdiffstats
path: root/src/main.c
blob: 1d9daaaa17af8cc262ce1bd8a2b468c732f75424 (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <libwebsockets.h>
#include <assert.h>
#include <signal.h>
#include <cjson/cJSON.h>
#include <json.c>
#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);
		switch (i.type) {
			case DC_API_USER:
				fprintf(stderr, "DC_API_USER: %s#%04d %llu\n", i.user->username,
						i.user->discriminator, i.user->id);
				break;
			case DC_API_CHANNEL:
				fprintf(stderr, "DC_API_CHANNEL participants: %u, type: %s\n",
						i.channel->users_length,
						dc_channel_type_str[i.channel->type]);
				break;
			case DC_API_LOGIN:
				if (i.status & DC_CAPTCHA_NEEDED)
					fprintf(stderr, "DC_CAPTCHA_NEEDED\n");
				break;
			default:
				break;
		}
	}
	/* dc_ui(argc, argv); */
	dc_program_free(p, DC_UNSET);
	return 0;
}