#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;
}