added cmd_bots (lists all bots)
[NeonServV5.git] / src / cmd_global_bots.c
1 /* cmd_global_bots.c - NeonServ v5.2
2  * Copyright (C) 2011  Philipp Kreil (pk910)
3  * 
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  * 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  * 
14  * You should have received a copy of the GNU General Public License 
15  * along with this program. If not, see <http://www.gnu.org/licenses/>. 
16  */
17
18 #include "cmd_global.h"
19
20 /*
21 * argv[0]    (optional) class name
22 */
23
24 CMD_BIND(global_cmd_bots) {
25     struct Table *table;
26     MYSQL_RES *res, *res2;
27     MYSQL_ROW row, row2;
28     printf_mysql_query("SELECT `active`, `nick`, `server`, `port`, `pass`, `botclass`, `textbot`, `queue`, `defaulttrigger`, `max_channels`, `register_priority`, `id` FROM `bots`");
29     res = mysql_use();
30     table = table_init(6, mysql_num_rows(res) + 1, 0);
31     char *content[5];
32     content[0] = get_language_string(user, "NS_BOTS_NICK");
33     content[1] = get_language_string(user, "NS_BOTS_SERVER");
34     content[2] = get_language_string(user, "NS_BOTS_CLASS");
35     content[3] = get_language_string(user, "NS_BOTS_FLAGS");
36     content[4] = get_language_string(user, "NS_BOTS_CHANNELS");
37     content[5] = get_language_string(user, "NS_BOTS_TRIGGER");
38     table_add(table, content);
39     char botnick[NICKLEN + 3];
40     char botserver[MAXLEN];
41     char botflags[10];
42     int flagspos;
43     char botchans[20];
44     while ((row = mysql_fetch_row(res)) != NULL) {
45         sprintf(botnick, (strcmp(row[0], "0") ? "%s" : "\00315%s\003"), row[1]);
46         contents[0] = botnick;
47         sprintf(botserver, (strcmp(row[4], "") ? "%s:%s:*" : "%s:%s"), row[2], row[3]);
48         contents[1] = botserver;
49         contents[2] = resolve_botid(atoi(row[5]));
50         flagspos = 0;
51         if(!strcmp(row[6], "1"))
52             botflags[flagspos++] = 't';
53         if(!strcmp(row[7], "1"))
54             botflags[flagspos++] = 'q';
55         botflags[flagspos] = '\0';
56         contents[3] = botflags;
57         printf_mysql_query("SELECT COUNT(*) FROM `bot_channels` WHERE `botid` = '%s'", row[11]);
58         res2 = mysql_use();
59         row2 = mysql_fetch_row(res2);
60         sprintf(botchans, "%s/%s", row2[0], row[9]);
61         contents[4] = botchans;
62         contents[5] = row[8];
63     }
64     char **table_lines = table_end(table);
65     for(i = 0; i < table->entrys; i++) {
66         reply(getTextBot(), user, table_lines[i]);
67     }
68 }