tried to reorder the program structure and build process
[NeonServV5.git] / src / cmd_neonserv_events.c
1
2 #include "cmd_neonserv.h"
3
4 /*
5 * argv[0]     time
6 * argv[1-*]   match
7 */
8
9 CMD_BIND(neonserv_cmd_events) {
10     char *str_match;
11     int duration = (argc ? strToTime(user, argv[0]) : 0);
12     if(argc > (duration ? 1 : 0))
13         str_match = merge_argv(argv, (duration ? 1 : 0), argc);
14     else
15         str_match = "";
16     if(!duration) duration = (60*60*24);
17     MYSQL_RES *res;
18     MYSQL_ROW row;
19     printf_mysql_query("SELECT `time`, `auth`, `nick`, `command` FROM `events` WHERE `cid` = '%d' AND `time` > '%lu' ORDER BY `time` ASC", chan->channel_id, ((unsigned long) time(0) - duration));
20     res = mysql_use();
21     int skip = mysql_num_rows(res) - 100;
22     int count = 0;
23     char timeBuf[50];
24     struct tm *timeinfo;
25     time_t event_time;
26     if(skip < 0) skip = 0;
27     reply(getTextBot(), user, "NS_EVENTS_HEADER");
28     while ((row = mysql_fetch_row(res)) != NULL) {
29         if(skip) {
30             skip--;
31             continue;
32         }
33         if(*str_match && match(str_match, row[3])) continue;
34         count++;
35         event_time = (time_t) atol(row[0]);
36         timeinfo = localtime(&event_time);
37         strftime(timeBuf, 80, "%X %x", timeinfo);
38         reply(getTextBot(), user, "[%s] [%s:%s]: %s", timeBuf, row[2], row[1], row[3]);
39     }
40     reply(getTextBot(), user, "NS_TABLE_COUNT", count);
41 }