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) {
206 printf_mysql_query("SELECT `helpserv_support`, `helpserv_public`, `helpserv_intern`, `helpserv_intern_announce` FROM `helpserv_settings` WHERE `helpserv_botid` = '%d'", client->clientid);
208 if (!(row = mysql_fetch_row(res))) return;
209 //check if the user is a supporter (access in the support channel)
210 if((user->flags & USERFLAG_ISAUTHED)) {
213 if(user->flags & USERFLAG_HAS_USERID)
214 userid = user->user_id;
216 printf_mysql_query("SELECT `user_id` FROM `users` WHERE `user_user` = '%s'", escape_string(user->auth));
218 if ((row2 = mysql_fetch_row(res)) != NULL) {
219 userid = atoi(row2[0]);
220 user->user_id = userid;
221 user->flags |= USERFLAG_HAS_USERID;
225 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]));
227 if ((row2 = mysql_fetch_row(res)) != NULL) {
228 int cflags = atoi(row2[1]);
229 if(!(cflags & DB_CHANUSER_SUSPENDED))
230 caccess = atoi(row2[0]);
232 if(caccess) return; //ignore messages from supporters
234 //check if the user is in one of the bot's channels
235 struct ChanUser *chanuser;
236 struct ChanNode *chan;
237 for(chanuser = getUserChannels(target, NULL); chanuser; chanuser = getUserChannels(target, chanuser)) {
238 chan = chanuser->chan;
239 if((!stricmp(chan->name, row[0]) || (row[1] && !stricmp(chan->name, row[1]))) && isUserOnChan(user, chan))
244 reply(client, user, "NH_NOT_ON_CHAN_2", row[0], row[1]);
246 reply(client, user, "NH_NOT_ON_CHAN_1", row[0]);
249 //check if there is already a support request
251 if(client->flags & SOCKET_HAVE_HELPNODE) {
252 struct NeonHelpNode *helpnode;
253 for(helpnode = client->botclass_helpnode; helpnode; helpnode = helpnode->next) {
254 if(helpnode->user == user) {
255 //simply append the message to the database
256 printf_mysql_query("SELECT `text` FROM `helpserv_requests` WHERE `id` = %d", helpnode->suppid);
258 if ((row2 = mysql_fetch_row(res)) != NULL) {
259 char *old_msg = escape_string(row2[0]);
260 char *new_msg = escape_string(message);
261 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);
269 struct NeonHelpNode *helpnode = malloc(sizeof(*helpnode));
270 if(!helpnode) return;
271 helpnode->user = user;
272 helpnode->logchan = getChanByName(row[0]);
273 helpnode->status = 0;
274 helpnode->announce = (row[2] && strcmp(row[3], "0") ? 1 : 0);
275 if(helpnode->announce) {
277 sprintf(nameBuf, "neonhelp_%d", client->clientid);
278 if(!timeq_name_exists(nameBuf)) {
279 int *cidptr = malloc(sizeof(int));
280 *cidptr = client->clientid;
281 timeq_add_name(nameBuf, 300, module_id, neonhelp_remind_open_requests, cidptr);
284 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));
285 helpnode->suppid = (int) mysql_insert_id(get_mysql_conn());
286 helpnode->log = NULL;
287 helpnode->next = ((client->flags & SOCKET_HAVE_HELPNODE) ? client->botclass_helpnode : NULL);
288 client->botclass_helpnode = helpnode;
289 client->flags |= SOCKET_HAVE_HELPNODE;
290 //build the user reply...
291 char user_reply[MAXLEN];
292 int user_reply_pos = 0;
293 char reply_buff[MAXLEN];
294 //1st part: NH_REQUEST_RECORDED
295 strcpy(user_reply + user_reply_pos, build_language_string(user, reply_buff, "NH_REQUEST_RECORDED", helpnode->suppid));
296 user_reply_pos += strlen(reply_buff);
297 //2nd part: NH_REQUEST_OTHERS_0 / NH_REQUEST_OTHERS_1 / NH_REQUEST_OTHERS_2
298 user_reply[user_reply_pos++] = ' ';
300 strcpy(user_reply + user_reply_pos, build_language_string(user, reply_buff, (others ? "NH_REQUEST_OTHERS_1" : "NH_REQUEST_OTHERS_0")));
302 strcpy(user_reply + user_reply_pos, build_language_string(user, reply_buff, "NH_REQUEST_OTHERS_2", others));
303 user_reply_pos += strlen(reply_buff);
304 //3th part: NH_REQUEST_FOOTER_1 / NH_REQUEST_FOOTER_2
305 user_reply[user_reply_pos++] = ' ';
307 strcpy(user_reply + user_reply_pos, build_language_string(user, reply_buff, "NH_REQUEST_FOOTER_2", row[0], row[1]));
309 strcpy(user_reply + user_reply_pos, build_language_string(user, reply_buff, "NH_REQUEST_FOOTER_1", row[0]));
310 user_reply_pos += strlen(reply_buff);
311 reply(client, user, "%s", user_reply);
312 //sent a message to the internal channel / onotice to supp channel
313 build_language_string(user, reply_buff, "NH_NEW_REQUEST", helpnode->suppid, user->nick, message);
315 putsock(client, "PRIVMSG %s :%s", row[2], reply_buff);
317 putsock(client, "NOTICE @%s :%s", row[0], reply_buff);
321 static TIMEQ_CALLBACK(neonhelp_remind_open_requests) {
322 int clientid = *((int*)data);
325 printf_mysql_query("SELECT `helpserv_support`, `helpserv_public`, `helpserv_intern`, `helpserv_intern_announce` FROM `helpserv_settings` WHERE `helpserv_botid` = '%d'", clientid);
327 if (!(row = mysql_fetch_row(res)) || !row[2]) {
331 struct ClientSocket *client;
332 for(client = getBots(SOCKET_FLAG_READY, NULL); client; client = getBots(SOCKET_FLAG_READY, client)) {
333 if(client->clientid == clientid)
340 //count open requests
342 struct NeonHelpNode *helpnode;
343 if(client->flags & SOCKET_HAVE_HELPNODE) {
344 for(helpnode = client->botclass_helpnode; helpnode; helpnode = helpnode->next) {
345 if(helpnode->status == 0) {
352 sprintf(nameBuf, "neonhelp_%d", client->clientid);
353 if(!timeq_name_exists(nameBuf)) {
354 timeq_add_name(nameBuf, 300, module_id, neonhelp_remind_open_requests, data);
356 char replybuf[MAXLEN];
357 build_language_string(NULL, replybuf, (requests == 1 ? "NH_REMIND_OPEN_REQUESTS_1" : "NH_REMIND_OPEN_REQUESTS_2"), requests);
358 putsock(client, "PRIVMSG %s :%s", row[2], replybuf);
363 static void neonhelp_event_chanmsg(struct UserNode *user, struct ChanNode *chan, char *message) {
364 char logline[MAXLEN];
365 sprintf(logline, "<%s> %s", user->nick, message);
366 struct ClientSocket *client;
367 for(client = getBots(SOCKET_FLAG_READY, NULL); client; client = getBots(SOCKET_FLAG_READY, client)) {
368 if(client->botid == BOTID) {
369 struct NeonHelpNode *helpnode;
370 if(client->flags & SOCKET_HAVE_HELPNODE) {
371 for(helpnode = client->botclass_helpnode; helpnode; helpnode = helpnode->next) {
372 if(helpnode->logchan == chan && helpnode->status == 1) {
374 helpnode->log = calloc(LOGBUFFERLINES, sizeof(char*));
375 if(!helpnode->log) return;
378 for(i = 0; i < LOGBUFFERLINES; i++) {
379 if(!helpnode->log[i]) {
380 helpnode->log[i] = strdup(logline);
384 if(i == LOGBUFFERLINES) {
385 //write buffer to database
386 char logbuff[MAXLEN * LOGBUFFERLINES];
388 for(i = 0; i < LOGBUFFERLINES; i++) {
389 len += sprintf(logbuff + len, "%s\n", helpnode->log[i]);
390 free(helpnode->log[i]);
391 helpnode->log[i] = NULL;
393 printf_long_mysql_query(1024 + len, "UPDATE `helpserv_requests` SET `log` = CONCAT(`log`, '%s') WHERE `id` = %d", escape_string(logbuff), helpnode->suppid);
403 void neonhelp_destroy_support_request(struct ClientSocket *client, struct NeonHelpNode *helpnode, int do_reply) {
404 //write buffer to database
405 char logbuff[MAXLEN * LOGBUFFERLINES];
409 for(i = 0; i < LOGBUFFERLINES; i++) {
410 if(!helpnode->log[i]) break;
411 len += sprintf(logbuff + len, "%s\n", helpnode->log[i]);
412 free(helpnode->log[i]);
413 helpnode->log[i] = NULL;
418 printf_long_mysql_query(1024 + len, "UPDATE `helpserv_requests` SET `status`='2', `log` = CONCAT(`log`, '%s') WHERE `id` = %d", escape_string(logbuff), helpnode->suppid);
420 reply(client, helpnode->user, "NH_DELETED", helpnode->suppid);
425 void neonhelp_invite_active_requests(struct ClientSocket *client, struct ChanNode *support, struct ChanNode *public, struct UserNode *ignore_user) {
426 struct NeonHelpNode *helpnode;
427 if(public && client->flags & SOCKET_HAVE_HELPNODE) {
428 for(helpnode = client->botclass_helpnode; helpnode; helpnode = helpnode->next) {
429 if(helpnode->status == 1 && helpnode->user != ignore_user && !isUserOnChan(helpnode->user, support)) {
430 putsock(client, "INVITE %s %s", helpnode->user->nick, support->name);
436 static void neonhelp_event_kick(struct UserNode *user, struct ChanUser *target, char *reason) {
437 struct ClientSocket *client;
440 struct ChanNode *support, *public;
442 for(client = getBots(SOCKET_FLAG_READY, NULL); client; client = getBots(SOCKET_FLAG_READY, client)) {
443 if(client->botid == BOTID && isUserOnChan(client->user, target->chan)) {
445 struct NeonHelpNode *helpnode, *prev_helpnode = NULL;
446 if(client->flags & SOCKET_HAVE_HELPNODE) {
447 for(helpnode = client->botclass_helpnode; helpnode; helpnode = helpnode->next) {
448 if(helpnode->user == target->user) {
452 prev_helpnode = helpnode;
455 if(!userHasRequest) continue;
456 printf_mysql_query("SELECT `helpserv_support`, `helpserv_public`, `helpserv_intern` FROM `helpserv_settings` WHERE `helpserv_botid` = '%d'", client->clientid);
458 if (!(row = mysql_fetch_row(res))) continue;
459 support = getChanByName(row[0]);
460 public = (row[1] ? getChanByName(row[1]) : NULL);
461 if(target->chan == support || !((support && isUserOnChan(target->user, support)) || (public && isUserOnChan(target->user, public)))) {
462 if(helpnode->status == 1 && target->chan != support) {
463 putsock(client, "MODE %s -i", support->name); //clear invite list
464 if(isModeSet(support->modes, 'i'))
465 putsock(client, "MODE %s +i", support->name);
466 neonhelp_invite_active_requests(client, support, public, target->user);
468 //free the user's support request
470 prev_helpnode->next = helpnode->next;
472 client->botclass_helpnode = helpnode->next;
473 neonhelp_destroy_support_request(client, helpnode, 1);
479 static void neonhelp_event_part(struct ChanUser *target, int quit, char *reason) {
480 struct ClientSocket *client;
483 struct ChanNode *support, *public;
485 for(client = getBots(SOCKET_FLAG_READY, NULL); client; client = getBots(SOCKET_FLAG_READY, client)) {
486 if(client->botid == BOTID && isUserOnChan(client->user, target->chan)) {
488 struct NeonHelpNode *helpnode, *prev_helpnode = NULL;
489 if(client->flags & SOCKET_HAVE_HELPNODE) {
490 for(helpnode = client->botclass_helpnode; helpnode; helpnode = helpnode->next) {
491 if(helpnode->user == target->user) {
495 prev_helpnode = helpnode;
498 if(!userHasRequest) continue;
499 printf_mysql_query("SELECT `helpserv_support`, `helpserv_public`, `helpserv_intern` FROM `helpserv_settings` WHERE `helpserv_botid` = '%d'", client->clientid);
501 if (!(row = mysql_fetch_row(res))) continue;
502 support = getChanByName(row[0]);
503 public = (row[1] ? getChanByName(row[1]) : NULL);
504 if(target->chan == support || !((support && isUserOnChan(target->user, support)) || (public && isUserOnChan(target->user, public)))) {
505 if(helpnode->status == 1 && target->chan != support) {
506 putsock(client, "MODE %s -i", support->name); //clear invite list
507 if(isModeSet(support->modes, 'i'))
508 putsock(client, "MODE %s +i", support->name);
509 neonhelp_invite_active_requests(client, support, public, target->user);
511 //free the user's support request
513 prev_helpnode->next = helpnode->next;
515 client->botclass_helpnode = helpnode->next;
516 neonhelp_destroy_support_request(client, helpnode, 1);
522 static void neonhelp_event_invite(struct ClientSocket *client, struct UserNode *user, char *channel) {
523 if(client->botid != BOTID)
527 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);
529 if ((row = mysql_fetch_row(res)) == NULL) {
530 reply(client, user, "NS_INVITE_FAIL", channel, client->user->nick);
533 if(!strcmp(row[2], "1")) {
534 reply(client, user, "MODCMD_CHAN_SUSPENDED");
537 int botid = atoi(row[0]);
538 struct ClientSocket *bot;
539 for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) {
540 if(bot->clientid == botid)
544 struct ChanNode *chan = getChanByName(channel);
545 if(chan && isUserOnChan(bot->user, chan)) {
546 reply(client, user, "NS_INVITE_ON_CHAN", bot->user->nick, chan->name);
548 putsock(bot, "JOIN %s", channel);
552 void init_NeonHelp(int type) {
553 set_bot_alias(BOTID, BOTALIAS);
556 if(type == MODSTATE_REBIND) return;
559 bind_bot_ready(neonhelp_bot_ready, module_id);
560 bind_privmsg(neonhelp_event_privmsg, module_id);
561 bind_chanmsg(neonhelp_event_chanmsg, module_id);
562 bind_part(neonhelp_event_part, module_id);
563 bind_kick(neonhelp_event_kick, module_id);
564 bind_invite(neonhelp_event_invite, module_id);
566 set_trigger_callback(BOTID, module_id, neonhelp_trigger_callback);
568 register_default_language_table(msgtab);
571 void free_NeonHelp(int type) {
572 unbind_allcmd(BOTID);
573 if(type == MODSTATE_STARTSTOP) {
574 //disconnect all our bots
575 struct ClientSocket *client;
576 for(client = getBots(0, NULL); client; client = getBots(0, client)) {
577 if(client->botid == BOTID) {
578 unbind_botwise_allcmd(0, client->clientid);
579 close_socket(client);