1 /* bot_NeonHelp.c - NeonServ v5.6
2 * Copyright (C) 2011-2012 Philipp Kreil (pk910)
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.
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.
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/>.
17 #include "../module.h"
20 #include "bot_NeonHelp.h"
21 #include "../../modcmd.h"
22 #include "cmd_neonhelp.h"
23 #include "../../lang.h"
24 #include "../../mysqlConn.h"
25 #include "../../ClientSocket.h"
26 #include "../../UserNode.h"
27 #include "../../ChanNode.h"
28 #include "../../ChanUser.h"
29 #include "../../IRCEvents.h"
30 #include "../../IRCParser.h"
31 #include "../../bots.h"
32 #include "../../DBHelper.h"
33 #include "../../WHOHandler.h"
35 #define BOTID NEONHELP_BOTID
36 #define BOTALIAS "NeonHelp"
38 static const struct default_language_entry msgtab[] = {
39 {"NH_NOT_ON_CHAN_1", "You cannot open this request as you are not in %s."}, /* {ARGS: "#test"} */
40 {"NH_NOT_ON_CHAN_2", "You cannot open this request as you are not in %s or %s."}, /* {ARGS: "test", "#test-support"} */
41 {"NH_REQUEST_RECORDED", "Your message has been recorded and assigned request ID#%d A helper should contact you shortly."}, /* {ARGS: 5} */
42 {"NH_REQUEST_OTHERS_0", "There are no other unhandled requests."},
43 {"NH_REQUEST_OTHERS_1", "There is 1 other unhandled request."},
44 {"NH_REQUEST_OTHERS_2", "There are %d other unhandled requests."}, /* {ARGS: 1337} */
45 {"NH_REQUEST_FOOTER_1", "Everything you tell me until you are helped (or you leave %1$s) will be recorded. If you part %1$s, your request will be lost."}, /* {ARGS: "#test"} */
46 {"NH_REQUEST_FOOTER_2", "Everything you tell me until you are helped (or you leave %1$s or %2$s) will be recorded. If you part %1$s or %2$s, your request will be lost."}, /* {ARGS: "#test", "#test-support"} */
47 {"NH_NEW_REQUEST", "New request #%d by %s: %s"}, /* {ARGS: 5, "pk910", "Help, I've fallen and I can't get up!"} */
48 {"NH_NEXT_NONE", "No more requests."},
49 {"NH_NEXT_NOT_FOUND", "No request found."},
50 {"NH_NEXT_HEADER", "$bNext request: #%d %s$b"}, /* {ARGS: 5, "pk910"} */
51 {"NH_NEXT_HELPER", "Your helper for request ID#%d is %s (Current nick: %s)."}, /* {ARGS: 5, "pk910", "Skynet"} */
52 {"NH_NEXT_JOIN", "Please /join %s now."}, /* {ARGS: "#test-support"} */
53 {"NH_DELETED", "Your request ID#%d has been deleted."}, /* {ARGS: 5} */
54 {"NH_DELETED_STAFF", "Request deleted: #%d (%s)"}, /* {ARGS: 5, "pk910"} */
55 {"NH_REMIND_OPEN_REQUESTS_1", "There is %d unhandled request!"}, /* {ARGS: 1} */
56 {"NH_REMIND_OPEN_REQUESTS_2", "There are %d unhandled requests!"}, /* {ARGS: 4} */
57 {"NH_REQUESTS_HEADER_ID", "ID"},
58 {"NH_REQUESTS_HEADER_STATUS", "State"},
59 {"NH_REQUESTS_HEADER_NICK", "Nick"},
60 {"NH_REQUESTS_HEADER_TIME", "Time"},
61 {"NH_REQUESTS_HEADER_STATUS", "State"},
62 {"NH_REQUESTS_HEADER_AUTH", "Auth"},
63 {"NH_REQUESTS_HEADER_MASK", "Mask"},
64 {"NH_REQUESTS_HEADER_REQUEST", "Question"},
65 {"NH_REQUESTS_STATE_ACTIVE", "active"},
66 {"NH_REQUESTS_STATE_PENDING", "pending"},
67 {"NH_REQUESTS_STATE_CLOSED", "closed"},
68 {"NH_REQUESTS_STATE_ERROR", "ERROR"},
69 {"NH_STATS_HEADER_USER", "User"},
70 {"NH_STATS_HEADER_LAST_24H", "last 24h"},
71 {"NH_STATS_HEADER_LAST_7DAY", "last 7d"},
72 {"NH_STATS_HEADER_LAST_30DAY", "last 30d"},
76 static void neonhelp_bot_ready(struct ClientSocket *client) {
77 if(client->botid != BOTID)
82 printf_mysql_query("SELECT `automodes`, `oper_user`, `oper_pass` FROM `bots` WHERE `id` = '%d'", client->clientid);
84 if ((row = mysql_fetch_row(res)) != NULL) {
85 if(row[1] && row[2]) {
86 putsock(client, "OPER %s %s", row[1], row[2]);
88 putsock(client, "MODE %s +%s", client->user->nick, row[0]);
91 printf_mysql_query("SELECT `channel_name`, `channel_key` FROM `bot_channels` LEFT JOIN `channels` ON `chanid` = `channel_id` WHERE `botid` = '%d' AND `suspended` = '0'", client->clientid);
94 while ((row = mysql_fetch_row(res)) != NULL) {
95 putsock(client, "JOIN %s %s", row[0], row[1]);
99 static void neonhelp_trigger_callback(int clientid, struct ChanNode *chan, char *trigger) {
102 loadChannelSettings(chan);
103 if(!(chan->flags & CHANFLAG_CHAN_REGISTERED)) {
104 strcpy(trigger, "!");
107 printf_mysql_query("SELECT `trigger`, `defaulttrigger` FROM `bot_channels` LEFT JOIN `bots` ON `botid` = `bots`.`id` WHERE `chanid` = '%d' AND `botclass` = '%d'", chan->channel_id, BOTID);
109 if(!(row = mysql_fetch_row(res))) {
110 strcpy(trigger, "!");
113 if(row[0] && *row[0])
114 strcpy(trigger, row[0]);
116 strcpy(trigger, ((row[1] && *row[1]) ? row[1] : "!"));
119 static void start_bots(int type) {
120 struct ClientSocket *client;
121 MYSQL_RES *res, *res2;
124 if(type == MODSTATE_STARTSTOP) {
125 printf_mysql_query("SELECT `nick`, `ident`, `realname`, `server`, `port`, `pass`, `textbot`, `id`, `queue`, `ssl`, `bind`, `secret` FROM `bots` WHERE `botclass` = '%d' AND `active` = '1'", BOTID);
128 while ((row = mysql_fetch_row(res)) != NULL) {
129 client = create_socket(row[3], atoi(row[4]), row[10], row[5], row[0], row[1], row[2]);
130 client->flags |= (strcmp(row[6], "0") ? SOCKET_FLAG_PREFERRED : 0);
131 client->flags |= (strcmp(row[8], "0") ? SOCKET_FLAG_USE_QUEUE : 0);
132 client->flags |= (strcmp(row[9], "0") ? SOCKET_FLAG_SSL : 0);
133 client->flags |= (strcmp(row[11], "0") ? SOCKET_FLAG_SECRET_BOT : 0);
134 client->flags |= SOCKET_FLAG_SILENT;
135 client->flags |= SOCKET_FLAG_REQUEST_INVITE | SOCKET_FLAG_REQUEST_OP;
136 client->botid = BOTID;
137 client->clientid = atoi(row[7]);
138 connect_socket(client);
139 //close old, still opened requests
140 printf_mysql_query("UPDATE `helpserv_requests` SET `status` = '2' WHERE `botid` = '%d'", client->clientid);
144 printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access`, `chan_access`, `flags` FROM `bot_binds` WHERE `botclass` = '%d'", BOTID);
146 while ((row = mysql_fetch_row(res2)) != NULL) {
147 if(bind_cmd_to_command(BOTID, row[0], row[1])) {
148 if(row[2] && strcmp(row[2], "")) {
149 bind_set_parameters(BOTID, row[0], row[2]);
152 bind_set_global_access(BOTID, row[0], atoi(row[3]));
155 bind_set_channel_access(BOTID, row[0], row[4]);
157 if(strcmp(row[5], "0"))
158 bind_set_bind_flags(BOTID, row[0], atoi(row[5]));
161 bind_unbound_required_functions(BOTID);
164 static void neonhelp_event_privmsg_async(struct ClientSocket *client, struct UserNode *user, struct UserNode *target, char *message);
165 static USERAUTH_CALLBACK(neonhelp_event_privmsg_nick_lookup);
166 struct neonhelp_event_privmsg_cache {
167 struct ClientSocket *client;
168 struct UserNode *user, *target;
172 static void neonhelp_event_privmsg(struct UserNode *user, struct UserNode *target, char *message) {
173 struct ClientSocket *client;
174 for(client = getBots(SOCKET_FLAG_READY, NULL); client; client = getBots(SOCKET_FLAG_READY, client)) {
175 if(client->user == target) {
176 if(client->botid != BOTID) return;
180 if(!client) return; //we got the message but we have no client that could receive it???
181 if(user->flags & USERFLAG_ISAUTHED) {
182 neonhelp_event_privmsg_async(client, user, target, message);
184 struct neonhelp_event_privmsg_cache *cache = malloc(sizeof(*cache));
186 cache->client = client;
188 cache->target = target;
189 cache->message = strdup(message);
190 get_userauth(user, module_id, neonhelp_event_privmsg_nick_lookup, cache);
194 static USERAUTH_CALLBACK(neonhelp_event_privmsg_nick_lookup) {
195 struct neonhelp_event_privmsg_cache *cache = data;
196 neonhelp_event_privmsg_async(cache->client, cache->user, cache->target, cache->message);
197 free(cache->message);
201 static TIMEQ_CALLBACK(neonhelp_remind_open_requests);
203 static void neonhelp_event_privmsg_async(struct ClientSocket *client, struct UserNode *user, struct UserNode *target, char *message) {
207 sprintf(setting, "modules.%s.need_auth", get_module_name(module_id));
208 if(get_int_field(setting) && !(user->flags & USERFLAG_ISAUTHED)) {
209 sprintf(setting, "modules.%s.need_auth_message", get_module_name(module_id));
211 if(!(reply_message = get_string_field(setting)))
212 reply_message = get_language_string(user, "MODCMD_AUTH_REQUIRED");
213 reply(client, user, "%s", reply_message);
216 printf_mysql_query("SELECT `helpserv_support`, `helpserv_public`, `helpserv_intern`, `helpserv_intern_announce` FROM `helpserv_settings` WHERE `helpserv_botid` = '%d'", client->clientid);
218 if (!(row = mysql_fetch_row(res))) return;
219 //check if the user is a supporter (access in the support channel)
220 if((user->flags & USERFLAG_ISAUTHED)) {
223 if(user->flags & USERFLAG_HAS_USERID)
224 userid = user->user_id;
226 printf_mysql_query("SELECT `user_id` FROM `users` WHERE `user_user` = '%s'", escape_string(user->auth));
228 if ((row2 = mysql_fetch_row(res)) != NULL) {
229 userid = atoi(row2[0]);
230 user->user_id = userid;
231 user->flags |= USERFLAG_HAS_USERID;
235 printf_mysql_query("SELECT `chanuser_access`, `chanuser_flags` FROM `chanusers` LEFT JOIN `channels` ON `chanuser_cid` = `channel_id` WHERE `chanuser_uid` = '%d' AND `channel_name` = '%s'", userid, escape_string(row[0]));
237 if ((row2 = mysql_fetch_row(res)) != NULL) {
238 int cflags = atoi(row2[1]);
239 if(!(cflags & DB_CHANUSER_SUSPENDED))
240 caccess = atoi(row2[0]);
242 if(caccess) return; //ignore messages from supporters
244 //check if the user is in one of the bot's channels
245 struct ChanUser *chanuser;
246 struct ChanNode *chan;
247 for(chanuser = getUserChannels(target, NULL); chanuser; chanuser = getUserChannels(target, chanuser)) {
248 chan = chanuser->chan;
249 if((!stricmp(chan->name, row[0]) || (row[1] && !stricmp(chan->name, row[1]))) && isUserOnChan(user, chan))
254 reply(client, user, "NH_NOT_ON_CHAN_2", row[0], row[1]);
256 reply(client, user, "NH_NOT_ON_CHAN_1", row[0]);
259 //check if there is already a support request
261 if(client->flags & SOCKET_HAVE_HELPNODE) {
262 struct NeonHelpNode *helpnode;
263 for(helpnode = client->botclass_helpnode; helpnode; helpnode = helpnode->next) {
264 if(helpnode->user == user) {
265 //simply append the message to the database
266 printf_mysql_query("SELECT `text` FROM `helpserv_requests` WHERE `id` = %d", helpnode->suppid);
268 if ((row2 = mysql_fetch_row(res)) != NULL) {
269 char *old_msg = escape_string(row2[0]);
270 char *new_msg = escape_string(message);
271 printf_long_mysql_query(1024 + strlen(old_msg) + strlen(new_msg), "UPDATE `helpserv_requests` SET `text` = '%s\n%s' WHERE `id` = %d", old_msg, new_msg, helpnode->suppid);
279 struct NeonHelpNode *helpnode = malloc(sizeof(*helpnode));
280 if(!helpnode) return;
281 helpnode->user = user;
282 helpnode->logchan = getChanByName(row[0]);
283 helpnode->status = 0;
284 helpnode->announce = (row[2] && strcmp(row[3], "0") ? 1 : 0);
285 if(helpnode->announce) {
287 sprintf(nameBuf, "neonhelp_%d", client->clientid);
288 if(!timeq_name_exists(nameBuf)) {
289 int *cidptr = malloc(sizeof(int));
290 *cidptr = client->clientid;
291 timeq_add_name(nameBuf, 300, module_id, neonhelp_remind_open_requests, cidptr);
294 printf_mysql_query("INSERT INTO `helpserv_requests` (`botid`, `host`, `hand`, `nick`, `status`, `supporter`, `time`, `text`) VALUES ('%d', '%s@%s', '%s', '%s', '0', '-1', UNIX_TIMESTAMP(), '%s')", client->clientid, escape_string(user->ident), escape_string(user->host), ((user->flags & USERFLAG_ISAUTHED) ? escape_string(user->auth) : "*"), escape_string(user->nick), escape_string(message));
295 helpnode->suppid = (int) mysql_insert_id(get_mysql_conn());
296 helpnode->log = NULL;
297 helpnode->next = ((client->flags & SOCKET_HAVE_HELPNODE) ? client->botclass_helpnode : NULL);
298 client->botclass_helpnode = helpnode;
299 client->flags |= SOCKET_HAVE_HELPNODE;
300 //build the user reply...
301 char user_reply[MAXLEN];
302 int user_reply_pos = 0;
303 char reply_buff[MAXLEN];
304 //1st part: NH_REQUEST_RECORDED
305 strcpy(user_reply + user_reply_pos, build_language_string(user, reply_buff, "NH_REQUEST_RECORDED", helpnode->suppid));
306 user_reply_pos += strlen(reply_buff);
307 //2nd part: NH_REQUEST_OTHERS_0 / NH_REQUEST_OTHERS_1 / NH_REQUEST_OTHERS_2
308 user_reply[user_reply_pos++] = ' ';
310 strcpy(user_reply + user_reply_pos, build_language_string(user, reply_buff, (others ? "NH_REQUEST_OTHERS_1" : "NH_REQUEST_OTHERS_0")));
312 strcpy(user_reply + user_reply_pos, build_language_string(user, reply_buff, "NH_REQUEST_OTHERS_2", others));
313 user_reply_pos += strlen(reply_buff);
314 //3th part: NH_REQUEST_FOOTER_1 / NH_REQUEST_FOOTER_2
315 user_reply[user_reply_pos++] = ' ';
317 strcpy(user_reply + user_reply_pos, build_language_string(user, reply_buff, "NH_REQUEST_FOOTER_2", row[0], row[1]));
319 strcpy(user_reply + user_reply_pos, build_language_string(user, reply_buff, "NH_REQUEST_FOOTER_1", row[0]));
320 user_reply_pos += strlen(reply_buff);
321 reply(client, user, "%s", user_reply);
322 //sent a message to the internal channel / onotice to supp channel
323 build_language_string(user, reply_buff, "NH_NEW_REQUEST", helpnode->suppid, user->nick, message);
325 putsock(client, "PRIVMSG %s :%s", row[2], reply_buff);
327 putsock(client, "NOTICE @%s :%s", row[0], reply_buff);
331 static TIMEQ_CALLBACK(neonhelp_remind_open_requests) {
332 int clientid = *((int*)data);
335 printf_mysql_query("SELECT `helpserv_support`, `helpserv_public`, `helpserv_intern`, `helpserv_intern_announce` FROM `helpserv_settings` WHERE `helpserv_botid` = '%d'", clientid);
337 if (!(row = mysql_fetch_row(res)) || !row[2]) {
341 struct ClientSocket *client;
342 for(client = getBots(SOCKET_FLAG_READY, NULL); client; client = getBots(SOCKET_FLAG_READY, client)) {
343 if(client->clientid == clientid)
350 //count open requests
352 struct NeonHelpNode *helpnode;
353 if(client->flags & SOCKET_HAVE_HELPNODE) {
354 for(helpnode = client->botclass_helpnode; helpnode; helpnode = helpnode->next) {
355 if(helpnode->status == 0) {
362 sprintf(nameBuf, "neonhelp_%d", client->clientid);
363 if(!timeq_name_exists(nameBuf)) {
364 timeq_add_name(nameBuf, 300, module_id, neonhelp_remind_open_requests, data);
366 char replybuf[MAXLEN];
367 build_language_string(NULL, replybuf, (requests == 1 ? "NH_REMIND_OPEN_REQUESTS_1" : "NH_REMIND_OPEN_REQUESTS_2"), requests);
368 putsock(client, "PRIVMSG %s :%s", row[2], replybuf);
373 static void neonhelp_event_chanmsg(struct UserNode *user, struct ChanNode *chan, char *message) {
374 char logline[MAXLEN];
375 sprintf(logline, "<%s> %s", user->nick, message);
376 struct ClientSocket *client;
377 for(client = getBots(SOCKET_FLAG_READY, NULL); client; client = getBots(SOCKET_FLAG_READY, client)) {
378 if(client->botid == BOTID) {
379 struct NeonHelpNode *helpnode;
380 if(client->flags & SOCKET_HAVE_HELPNODE) {
381 for(helpnode = client->botclass_helpnode; helpnode; helpnode = helpnode->next) {
382 if(helpnode->logchan == chan && helpnode->status == 1) {
384 helpnode->log = calloc(LOGBUFFERLINES, sizeof(char*));
385 if(!helpnode->log) return;
388 for(i = 0; i < LOGBUFFERLINES; i++) {
389 if(!helpnode->log[i]) {
390 helpnode->log[i] = strdup(logline);
394 if(i == LOGBUFFERLINES) {
395 //write buffer to database
396 char logbuff[MAXLEN * LOGBUFFERLINES];
398 for(i = 0; i < LOGBUFFERLINES; i++) {
399 len += sprintf(logbuff + len, "%s\n", helpnode->log[i]);
400 free(helpnode->log[i]);
401 helpnode->log[i] = NULL;
403 printf_long_mysql_query(1024 + len, "UPDATE `helpserv_requests` SET `log` = CONCAT(`log`, '%s') WHERE `id` = %d", escape_string(logbuff), helpnode->suppid);
413 void neonhelp_destroy_support_request(struct ClientSocket *client, struct NeonHelpNode *helpnode, int do_reply) {
414 //write buffer to database
415 char logbuff[MAXLEN * LOGBUFFERLINES];
419 for(i = 0; i < LOGBUFFERLINES; i++) {
420 if(!helpnode->log[i]) break;
421 len += sprintf(logbuff + len, "%s\n", helpnode->log[i]);
422 free(helpnode->log[i]);
423 helpnode->log[i] = NULL;
428 printf_long_mysql_query(1024 + len, "UPDATE `helpserv_requests` SET `status`='2', `log` = CONCAT(`log`, '%s') WHERE `id` = %d", escape_string(logbuff), helpnode->suppid);
430 reply(client, helpnode->user, "NH_DELETED", helpnode->suppid);
435 void neonhelp_invite_active_requests(struct ClientSocket *client, struct ChanNode *support, struct ChanNode *public, struct UserNode *ignore_user) {
436 struct NeonHelpNode *helpnode;
437 if(public && client->flags & SOCKET_HAVE_HELPNODE) {
438 for(helpnode = client->botclass_helpnode; helpnode; helpnode = helpnode->next) {
439 if(helpnode->status == 1 && helpnode->user != ignore_user && !isUserOnChan(helpnode->user, support)) {
440 putsock(client, "INVITE %s %s", helpnode->user->nick, support->name);
446 static void neonhelp_event_kick(struct UserNode *user, struct ChanUser *target, char *reason) {
447 struct ClientSocket *client;
450 struct ChanNode *support, *public;
452 for(client = getBots(SOCKET_FLAG_READY, NULL); client; client = getBots(SOCKET_FLAG_READY, client)) {
453 if(client->botid == BOTID && isUserOnChan(client->user, target->chan)) {
455 struct NeonHelpNode *helpnode, *prev_helpnode = NULL;
456 if(client->flags & SOCKET_HAVE_HELPNODE) {
457 for(helpnode = client->botclass_helpnode; helpnode; helpnode = helpnode->next) {
458 if(helpnode->user == target->user) {
462 prev_helpnode = helpnode;
465 if(!userHasRequest) continue;
466 printf_mysql_query("SELECT `helpserv_support`, `helpserv_public`, `helpserv_intern` FROM `helpserv_settings` WHERE `helpserv_botid` = '%d'", client->clientid);
468 if (!(row = mysql_fetch_row(res))) continue;
469 support = getChanByName(row[0]);
470 public = (row[1] ? getChanByName(row[1]) : NULL);
471 if(target->chan == support || !((support && isUserOnChan(target->user, support)) || (public && isUserOnChan(target->user, public)))) {
472 if(helpnode->status == 1 && target->chan != support) {
473 putsock(client, "MODE %s -i", support->name); //clear invite list
474 if(isModeSet(support->modes, 'i'))
475 putsock(client, "MODE %s +i", support->name);
476 neonhelp_invite_active_requests(client, support, public, target->user);
478 //free the user's support request
480 prev_helpnode->next = helpnode->next;
482 client->botclass_helpnode = helpnode->next;
483 neonhelp_destroy_support_request(client, helpnode, 1);
489 static void neonhelp_event_part(struct ChanUser *target, int quit, char *reason) {
490 struct ClientSocket *client;
493 struct ChanNode *support, *public;
495 for(client = getBots(SOCKET_FLAG_READY, NULL); client; client = getBots(SOCKET_FLAG_READY, client)) {
496 if(client->botid == BOTID && isUserOnChan(client->user, target->chan)) {
498 struct NeonHelpNode *helpnode, *prev_helpnode = NULL;
499 if(client->flags & SOCKET_HAVE_HELPNODE) {
500 for(helpnode = client->botclass_helpnode; helpnode; helpnode = helpnode->next) {
501 if(helpnode->user == target->user) {
505 prev_helpnode = helpnode;
508 if(!userHasRequest) continue;
509 printf_mysql_query("SELECT `helpserv_support`, `helpserv_public`, `helpserv_intern` FROM `helpserv_settings` WHERE `helpserv_botid` = '%d'", client->clientid);
511 if (!(row = mysql_fetch_row(res))) continue;
512 support = getChanByName(row[0]);
513 public = (row[1] ? getChanByName(row[1]) : NULL);
514 if(target->chan == support || !((support && isUserOnChan(target->user, support)) || (public && isUserOnChan(target->user, public)))) {
515 if(helpnode->status == 1 && target->chan != support) {
516 putsock(client, "MODE %s -i", support->name); //clear invite list
517 if(isModeSet(support->modes, 'i'))
518 putsock(client, "MODE %s +i", support->name);
519 neonhelp_invite_active_requests(client, support, public, target->user);
521 //free the user's support request
523 prev_helpnode->next = helpnode->next;
525 client->botclass_helpnode = helpnode->next;
526 neonhelp_destroy_support_request(client, helpnode, 1);
532 static void neonhelp_event_invite(struct ClientSocket *client, struct UserNode *user, char *channel) {
533 if(client->botid != BOTID)
537 printf_mysql_query("SELECT `botid`, `bot_channels`.`id`, `suspended` FROM `bot_channels` LEFT JOIN `bots` ON `bot_channels`.`botid` = `bots`.`id` LEFT JOIN `channels` ON `chanid` = `channel_id` WHERE `channel_name` = '%s' AND `botclass` = '%d'", escape_string(channel), client->botid);
539 if ((row = mysql_fetch_row(res)) == NULL) {
540 reply(client, user, "NS_INVITE_FAIL", channel, client->user->nick);
543 if(!strcmp(row[2], "1")) {
544 reply(client, user, "MODCMD_CHAN_SUSPENDED");
547 int botid = atoi(row[0]);
548 struct ClientSocket *bot;
549 for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) {
550 if(bot->clientid == botid)
554 struct ChanNode *chan = getChanByName(channel);
555 if(chan && isUserOnChan(bot->user, chan)) {
556 reply(client, user, "NS_INVITE_ON_CHAN", bot->user->nick, chan->name);
558 putsock(bot, "JOIN %s", channel);
562 void init_NeonHelp(int type) {
563 set_bot_alias(BOTID, BOTALIAS);
566 if(type == MODSTATE_REBIND) return;
569 bind_bot_ready(neonhelp_bot_ready, module_id);
570 bind_privmsg(neonhelp_event_privmsg, module_id);
571 bind_chanmsg(neonhelp_event_chanmsg, module_id);
572 bind_part(neonhelp_event_part, module_id);
573 bind_kick(neonhelp_event_kick, module_id);
574 bind_invite(neonhelp_event_invite, module_id);
576 set_trigger_callback(BOTID, module_id, neonhelp_trigger_callback);
578 register_default_language_table(msgtab);
581 void free_NeonHelp(int type) {
582 unbind_allcmd(BOTID);
583 if(type == MODSTATE_STARTSTOP) {
584 //disconnect all our bots
585 struct ClientSocket *client;
586 for(client = getBots(0, NULL); client; client = getBots(0, client)) {
587 if(client->botid == BOTID) {
588 unbind_botwise_allcmd(0, client->clientid);
589 close_socket(client);