summaryrefslogtreecommitdiff
path: root/main.c
blob: ec6ebb754a374ba8ddb26c2c02a044ea5e607172 (plain)
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
#include "db.h"
#include "log.h"
#include "tdutils.h"
#include "botd.h"
#include "logic.h"

#include <stdlib.h>
#include <string.h>

cmd_t cmd = {
        NULL,
        0,
        NULL,
        false,
        NULL,
        false
};

time_t start_time = 0;

int post_auth() {
    LOGI("OK");
    return 0;
}

static void ate(void) {
    db_close();
    td_free();
}

int main(int argc, char **argv) {
    start_time = time(NULL);
    atexit(&ate);
    parse_cmdline(argc, argv);
    LOGI("Initializing database ...");
    db_init();
    LOGI("Initializing TDLib ...");
    td_init();
    LOGI("Waiting for updates.");
    td_loop();
    return 0;
}

static void cb_store(bool succ) {}

int handle_message(struct TdUpdateNewMessage *update) {
    struct TdMessage *msg = update->message_;
    if (msg->content_->ID == CODE_MessageText &&
        !strncmp(((struct TdMessageText *) msg->content_)->text_->text_, "/stat", 5)) {
        stat(msg);
        return 0;
    }
    if (msg->sender_id_->ID == CODE_MessageSenderUser &&
        ((struct TdMessageSenderUser *) msg->sender_id_)->user_id_ == ADMIN) {
        if (msg->content_->ID == CODE_MessageText &&
            !strncmp(((struct TdMessageText *) msg->content_)->text_->text_, "/refresh", 8)) {
            refresh(msg);
            return 0;
        }
    }
    store(msg, &cb_store);
    return 0;
}