added some missing language strings and a internal channel reminder
[NeonServV5.git] / src / bot_NeonHelp.c
1 /* bot_NeonHelp.c - NeonServ v5.3
2  * Copyright (C) 2011-2012  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 "bot_NeonHelp.h"
19 #include "modcmd.h"
20 #include "cmd_neonhelp.h"
21 #include "lang.h"
22 #include "mysqlConn.h"
23 #include "ClientSocket.h"
24 #include "UserNode.h"
25 #include "ChanNode.h"
26 #include "ChanUser.h"
27 #include "IRCEvents.h"
28 #include "IRCParser.h"
29 #include "bots.h"
30 #include "DBHelper.h"
31 #include "WHOHandler.h"
32
33 #define BOTID 4
34 #define BOTALIAS "NeonHelp"
35
36 static const struct default_language_entry msgtab[] = {
37     {"NH_NOT_ON_CHAN_1", "You cannot open this request as you are not in %s."}, /* {ARGS: "#test"} */
38     {"NH_NOT_ON_CHAN_2", "You cannot open this request as you are not in %s or %s."}, /* {ARGS: "test", "#test-support"} */
39     {"NH_REQUEST_RECORDED", "Your message has been recorded and assigned request ID#%d A helper should contact you shortly."}, /* {ARGS: 5} */
40     {"NH_REQUEST_OTHERS_0", "There are no other unhandled requests."},
41     {"NH_REQUEST_OTHERS_1", "There is 1 other unhandled request."},
42     {"NH_REQUEST_OTHERS_2", "There are %d other unhandled requests."}, /* {ARGS: 1337} */
43     {"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"} */
44     {"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"} */
45     {"NH_NEW_REQUEST", "New request #%d by %s: %s"}, /* {ARGS: 5, "pk910", "Help, I've fallen and I can't get up!"} */
46     {"NH_NEXT_NONE", "No more requests."},
47     {"NH_NEXT_NOT_FOUND", "No request found."},
48     {"NH_NEXT_HEADER", "$bNext request: #%d %s$b"}, /* {ARGS: 5, "pk910"} */
49     {"NH_NEXT_HELPER", "Your helper for request ID#%d is %s (Current nick: %s)."}, /* {ARGS: 5, "pk910", "Skynet"} */
50     {"NH_NEXT_JOIN", "Please /join %s now."}, /* {ARGS: "#test-support"} */
51     {"NH_DELETED", "Your request ID#%d has been deleted."}, /* {ARGS: 5} */
52     {"NH_DELETED_STAFF", "Request deleted: #%d (%s)"}, /* {ARGS: 5, "pk910"} */
53     {"NH_REMIND_OPEN_REQUESTS_1", "There is %d unhandled request!"}, /* {ARGS: 1} */
54     {"NH_REMIND_OPEN_REQUESTS_2", "There are %d unhandled requests!"}, /* {ARGS: 4} */
55     {"NH_REQUESTS_HEADER_ID", "ID"},
56     {"NH_REQUESTS_HEADER_STATUS", "State"},
57     {"NH_REQUESTS_HEADER_NICK", "Nick"},
58     {"NH_REQUESTS_HEADER_TIME", "Time"},
59     {"NH_REQUESTS_HEADER_REQUEST", "Question"},
60     {"NH_REQUESTS_STATE_ACTIVE", "active"},
61     {"NH_REQUESTS_STATE_PENDING", "pending"},
62     {"NH_REQUESTS_STATE_ERROR", "ERROR"},
63     {NULL, NULL}
64 };
65
66 static void neonhelp_bot_ready(struct ClientSocket *client) {
67     MYSQL_RES *res;
68     MYSQL_ROW row;
69     
70     printf_mysql_query("SELECT `automodes` FROM `bots` WHERE `id` = '%d'", client->clientid);
71     res = mysql_use();
72     if ((row = mysql_fetch_row(res)) != NULL) {
73         putsock(client, "MODE %s +%s", client->user->nick, row[0]);
74     }
75     
76     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);
77     res = mysql_use();
78     
79     while ((row = mysql_fetch_row(res)) != NULL) {
80         putsock(client, "JOIN %s %s", row[0], row[1]);
81     }
82 }
83
84 static void neonhelp_trigger_callback(int clientid, struct ChanNode *chan, char *trigger) {
85     MYSQL_RES *res;
86     MYSQL_ROW row;
87     loadChannelSettings(chan);
88     if(!(chan->flags & CHANFLAG_CHAN_REGISTERED)) {
89         strcpy(trigger, "!");
90         return;
91     }
92     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);
93     res = mysql_use();
94     row = mysql_fetch_row(res);
95     if(row[0] && *row[0])
96         strcpy(trigger, row[0]);
97     else
98         strcpy(trigger, ((row[1] && *row[1]) ? row[1] : "!"));
99 }
100
101 static void start_bots() {
102     struct ClientSocket *client;
103     MYSQL_RES *res, *res2;
104     MYSQL_ROW row;
105     
106     printf_mysql_query("SELECT `nick`, `ident`, `realname`, `server`, `port`, `pass`, `textbot`, `id`, `queue`, `ssl`, `bind` FROM `bots` WHERE `botclass` = '%d' AND `active` = '1'", BOTID);
107     res = mysql_use();
108     
109     while ((row = mysql_fetch_row(res)) != NULL) {
110         client = create_socket(row[3], atoi(row[4]), row[10], row[5], row[0], row[1], row[2]);
111         client->flags |= (strcmp(row[6], "0") ? SOCKET_FLAG_PREFERRED : 0);
112         client->flags |= (strcmp(row[8], "0") ? SOCKET_FLAG_USE_QUEUE : 0);
113         client->flags |= (strcmp(row[9], "0") ? SOCKET_FLAG_SSL : 0);
114         client->flags |= SOCKET_FLAG_SILENT;
115         client->botid = BOTID;
116         client->clientid = atoi(row[7]);
117         connect_socket(client);
118         //close old, still opened requests
119         printf_mysql_query("UPDATE `helpserv_requests` SET `status` = '2' WHERE `botid` = '%d'", client->clientid);
120     }
121     
122     printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access`, `chan_access`, `flags` FROM `bot_binds` WHERE `botclass` = '%d'", BOTID);
123     res2 = mysql_use();
124     while ((row = mysql_fetch_row(res2)) != NULL) {
125         if(bind_cmd_to_command(BOTID, row[0], row[1])) {
126             if(row[2] && strcmp(row[2], "")) {
127                 bind_set_parameters(BOTID, row[0], row[2]);
128             }
129             if(row[3]) {
130                 bind_set_global_access(BOTID, row[0], atoi(row[3]));
131             }
132             if(row[4]) {
133                 bind_set_channel_access(BOTID, row[0], row[4]);
134             }
135             if(strcmp(row[5], "0"))
136                 bind_set_bind_flags(BOTID, row[0], atoi(row[5]));
137         }
138     }
139     bind_unbound_required_functions(BOTID);
140 }
141
142 static void neonhelp_event_privmsg_async(struct ClientSocket *client, struct UserNode *user, struct UserNode *target, char *message);
143 static USERAUTH_CALLBACK(neonhelp_event_privmsg_nick_lookup);
144 struct neonhelp_event_privmsg_cache {
145     struct ClientSocket *client;
146     struct UserNode *user, *target;
147     char *message;
148 };
149
150 static void neonhelp_event_privmsg(struct UserNode *user, struct UserNode *target, char *message) {
151     struct ClientSocket *client;
152     for(client = getBots(SOCKET_FLAG_READY, NULL); client; client = getBots(SOCKET_FLAG_READY, client)) {
153         if(client->user == target) {
154             if(client->botid != BOTID) return;
155             break;
156         }
157     }
158     if(!client) return; //we got the message but we have no client that could receive it???
159     if(user->flags & USERFLAG_ISAUTHED) {
160         neonhelp_event_privmsg_async(client, user, target, message);
161     } else {
162         struct neonhelp_event_privmsg_cache *cache = malloc(sizeof(*cache));
163         if(!cache) return;
164         cache->client = client;
165         cache->user = user;
166         cache->target = target;
167         cache->message = strdup(message);
168         get_userauth(user, neonhelp_event_privmsg_nick_lookup, cache);
169     }
170 }
171
172 static USERAUTH_CALLBACK(neonhelp_event_privmsg_nick_lookup) {
173     struct neonhelp_event_privmsg_cache *cache = data;
174     neonhelp_event_privmsg_async(cache->client, cache->user, cache->target, cache->message);
175     free(cache->message);
176     free(cache);
177 }
178
179 static TIMEQ_CALLBACK(neonhelp_remind_open_requests);
180
181 static void neonhelp_event_privmsg_async(struct ClientSocket *client, struct UserNode *user, struct UserNode *target, char *message) {
182     MYSQL_RES *res;
183     MYSQL_ROW row, row2;
184     printf_mysql_query("SELECT `helpserv_support`, `helpserv_public`, `helpserv_intern`, `helpserv_intern_announce` FROM `helpserv_settings` WHERE `helpserv_botid` = '%d'", client->clientid);
185     res = mysql_use();
186     if (!(row = mysql_fetch_row(res))) return;
187     //check if the user is a supporter (access in the support channel)
188     if((user->flags & USERFLAG_ISAUTHED)) {
189         int caccess = 0;
190         int userid;
191         if(user->flags & USERFLAG_HAS_USERID)
192             userid = user->user_id;
193         else {
194             printf_mysql_query("SELECT `user_id` FROM `users` WHERE `user_user` = '%s'", escape_string(user->auth));
195             res = mysql_use();
196             if ((row2 = mysql_fetch_row(res)) != NULL) {
197                 userid = atoi(row2[0]);
198                 user->user_id = userid;
199                 user->flags |= USERFLAG_HAS_USERID;
200             } else
201                 userid = 0;
202         }
203         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]));
204         res = mysql_use();
205         if ((row2 = mysql_fetch_row(res)) != NULL) {
206             int cflags = atoi(row2[1]);
207             if(!(cflags & DB_CHANUSER_SUSPENDED))
208                 caccess = atoi(row2[0]);
209         }
210         if(caccess) return; //ignore messages from supporters
211     }
212     //check if the user is in one of the bot's channels
213     struct ChanUser *chanuser;
214     struct ChanNode *chan;
215     for(chanuser = getUserChannels(target, NULL); chanuser; chanuser = getUserChannels(target, chanuser)) {
216         chan = chanuser->chan;
217         if((!stricmp(chan->name, row[0]) || (row[1] && !stricmp(chan->name, row[1]))) && isUserOnChan(user, chan))
218             break;
219     }
220     if(!chanuser) {
221         if(row[1])
222             reply(client, user, "NH_NOT_ON_CHAN_2", row[0], row[1]);
223         else
224             reply(client, user, "NH_NOT_ON_CHAN_1", row[0]);
225         return;
226     }
227     //check if there is already a support request
228     int others = 0;
229     if(client->flags & SOCKET_HAVE_HELPNODE) {
230         struct NeonHelpNode *helpnode;
231         for(helpnode = client->botclass_helpnode; helpnode; helpnode = helpnode->next) {
232             if(helpnode->user == user) {
233                 //simply append the message to the database
234                 printf_mysql_query("SELECT `text` FROM `helpserv_requests` WHERE `id` = %d", helpnode->suppid);
235                 res = mysql_use();
236                 if ((row2 = mysql_fetch_row(res)) != NULL) {
237                     char *old_msg = escape_string(row2[0]);
238                     char *new_msg = escape_string(message);
239                     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);
240                 }
241                 return;
242             }
243             others++;
244         }
245     }
246     //add new request
247     struct NeonHelpNode *helpnode = malloc(sizeof(*helpnode));
248     if(!helpnode) return;
249     helpnode->user = user;
250     helpnode->logchan = getChanByName(row[0]);
251     helpnode->status = 0;
252     helpnode->announce = (row[2] && strcmp(row[3], "0") ? 1 : 0);
253     if(helpnode->announce) {
254         char nameBuf[30];
255         sprintf(nameBuf, "neonhelp_%d", client->clientid);
256         if(!timeq_name_exists(nameBuf)) {
257             int *cidptr = malloc(sizeof(int));
258             *cidptr = client->clientid;
259             timeq_add_name(nameBuf, 300, neonhelp_remind_open_requests, cidptr);
260         }
261     }
262     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));
263     helpnode->suppid = (int) mysql_insert_id(mysql_conn);
264     helpnode->log = NULL;
265     helpnode->next = ((client->flags & SOCKET_HAVE_HELPNODE) ? client->botclass_helpnode : NULL);
266     client->botclass_helpnode = helpnode;
267     client->flags |= SOCKET_HAVE_HELPNODE;
268     //build the user reply...
269     char user_reply[MAXLEN];
270     int user_reply_pos = 0;
271     char reply_buff[MAXLEN];
272     //1st part: NH_REQUEST_RECORDED
273     strcpy(user_reply + user_reply_pos, build_language_string(user, reply_buff, "NH_REQUEST_RECORDED", helpnode->suppid));
274     user_reply_pos += strlen(reply_buff);
275     //2nd part: NH_REQUEST_OTHERS_0 / NH_REQUEST_OTHERS_1 / NH_REQUEST_OTHERS_2
276     user_reply[user_reply_pos++] = ' ';
277     if(others <= 1)
278         strcpy(user_reply + user_reply_pos, build_language_string(user, reply_buff, (others ? "NH_REQUEST_OTHERS_1" : "NH_REQUEST_OTHERS_0")));
279     else
280         strcpy(user_reply + user_reply_pos, build_language_string(user, reply_buff, "NH_REQUEST_OTHERS_2", others));
281     user_reply_pos += strlen(reply_buff);
282     //3th part: NH_REQUEST_FOOTER_1 / NH_REQUEST_FOOTER_2
283     user_reply[user_reply_pos++] = ' ';
284     if(row[1])
285         strcpy(user_reply + user_reply_pos, build_language_string(user, reply_buff, "NH_REQUEST_FOOTER_2", row[0], row[1]));
286     else
287         strcpy(user_reply + user_reply_pos, build_language_string(user, reply_buff, "NH_REQUEST_FOOTER_1", row[0]));
288     user_reply_pos += strlen(reply_buff);
289     reply(client, user, "%s", user_reply);
290     //sent a message to the internal channel / onotice to supp channel
291     build_language_string(user, reply_buff, "NH_NEW_REQUEST", helpnode->suppid, user->nick, message);
292     if(row[2]) {
293         putsock(client, "PRIVMSG %s :%s", row[2], reply_buff);
294     } else {
295         putsock(client, "NOTICE @%s :%s", row[0], reply_buff);
296     }
297 }
298
299 static TIMEQ_CALLBACK(neonhelp_remind_open_requests) {
300     int clientid = *((int*)data);
301     MYSQL_RES *res;
302     MYSQL_ROW row;
303     printf_mysql_query("SELECT `helpserv_support`, `helpserv_public`, `helpserv_intern`, `helpserv_intern_announce` FROM `helpserv_settings` WHERE `helpserv_botid` = '%d'", clientid);
304     res = mysql_use();
305     if (!(row = mysql_fetch_row(res)) || !row[2]) {
306         free(data);
307         return;
308     }
309     struct ClientSocket *client;
310     for(client = getBots(SOCKET_FLAG_READY, NULL); client; client = getBots(SOCKET_FLAG_READY, client)) {
311         if(client->clientid == clientid)
312             break;
313     }
314     if(!client) {
315         free(data);
316         return;
317     }
318     //count open requests
319     int requests = 0;
320     struct NeonHelpNode *helpnode;
321     if(client->flags & SOCKET_HAVE_HELPNODE) {
322         for(helpnode = client->botclass_helpnode; helpnode; helpnode = helpnode->next) {
323             if(helpnode->status == 0) {
324                 requests++;
325             }
326         }
327     }
328     if(requests) {
329         char nameBuf[30];
330         sprintf(nameBuf, "neonhelp_%d", client->clientid);
331         if(!timeq_name_exists(nameBuf)) {
332             timeq_add_name(nameBuf, 300, neonhelp_remind_open_requests, data);
333         }
334         char replybuf[MAXLEN];
335         build_language_string(NULL, replybuf, (requests == 1 ? "NH_REMIND_OPEN_REQUESTS_1" : "NH_REMIND_OPEN_REQUESTS_2"), requests);
336         putsock(client, "PRIVMSG %s :%s", row[2], replybuf);
337     } else
338         free(data);
339 }
340
341 static void neonhelp_event_chanmsg(struct UserNode *user, struct ChanNode *chan, char *message) {
342     char logline[MAXLEN];
343     sprintf(logline, "<%s> %s", user->nick, message);
344     struct ClientSocket *client;
345     for(client = getBots(SOCKET_FLAG_READY, NULL); client; client = getBots(SOCKET_FLAG_READY, client)) {
346         if(client->botid == BOTID) {
347             struct NeonHelpNode *helpnode;
348             if(client->flags & SOCKET_HAVE_HELPNODE) {
349                 for(helpnode = client->botclass_helpnode; helpnode; helpnode = helpnode->next) {
350                     if(helpnode->logchan == chan && helpnode->status == 1) {
351                         if(!helpnode->log) {
352                             helpnode->log = calloc(LOGBUFFERLINES, sizeof(char*));
353                             if(!helpnode->log) return;
354                         }
355                         int i;
356                         for(i = 0; i < LOGBUFFERLINES; i++) {
357                             if(!helpnode->log[i]) {
358                                 helpnode->log[i] = strdup(logline);
359                                 break;
360                             }
361                         }
362                         if(i == LOGBUFFERLINES) {
363                             //write buffer to database
364                             char logbuff[MAXLEN * LOGBUFFERLINES];
365                             int len = 0;
366                             for(i = 0; i < LOGBUFFERLINES; i++) {
367                                 len += sprintf(logbuff + len, "%s\n", helpnode->log[i]);
368                                 free(helpnode->log[i]);
369                                 helpnode->log[i] = NULL;
370                             }
371                             printf_long_mysql_query(1024 + len, "UPDATE `helpserv_requests` SET `log` = CONCAT(`log`, '%s') WHERE `id` = %d", escape_string(logbuff), helpnode->suppid);
372                         }
373                         break;
374                     }
375                 }
376             }
377         }
378     }
379 }
380
381 static void destroy_support_request(struct ClientSocket *client, struct NeonHelpNode *helpnode, int do_reply) {
382     //write buffer to database
383     char logbuff[MAXLEN * LOGBUFFERLINES];
384     int len = 0;
385     int i;
386     if(helpnode->log) {
387         for(i = 0; i < LOGBUFFERLINES; i++) {
388             if(!helpnode->log[i]) break;
389             len += sprintf(logbuff + len, "%s\n", helpnode->log[i]);
390             free(helpnode->log[i]);
391             helpnode->log[i] = NULL;
392         }
393         free(helpnode->log);
394     }
395     printf_long_mysql_query(1024 + len, "UPDATE `helpserv_requests` SET `status`='2', `log` = CONCAT(`log`, '%s') WHERE `id` = %d", escape_string(logbuff), helpnode->suppid);
396     if(do_reply) {
397         reply(client, helpnode->user, "NH_DELETED", helpnode->suppid);
398     }
399     free(helpnode);
400 }
401
402 static void neonhelp_event_kick(struct UserNode *user, struct ChanUser *target, char *reason) {
403     struct ClientSocket *client;
404     MYSQL_RES *res;
405     MYSQL_ROW row;
406     struct ChanNode *support, *public;
407     int userHasRequest;
408     for(client = getBots(SOCKET_FLAG_READY, NULL); client; client = getBots(SOCKET_FLAG_READY, client)) {
409         if(client->botid == BOTID && isUserOnChan(client->user, target->chan)) {
410             userHasRequest = 0;
411             struct NeonHelpNode *helpnode, *prev_helpnode = NULL;
412             if(client->flags & SOCKET_HAVE_HELPNODE) {
413                 for(helpnode = client->botclass_helpnode; helpnode; helpnode = helpnode->next) {
414                     if(helpnode->user == target->user) {
415                         userHasRequest = 1;
416                         break;
417                     } else
418                         prev_helpnode = helpnode;
419                 }
420             }
421             if(!userHasRequest) continue;
422             printf_mysql_query("SELECT `helpserv_support`, `helpserv_public`, `helpserv_intern` FROM `helpserv_settings` WHERE `helpserv_botid` = '%d'", client->clientid);
423             res = mysql_use();
424             if (!(row = mysql_fetch_row(res))) continue;
425             support = getChanByName(row[0]);
426             public = (row[1] ? getChanByName(row[1]) : NULL);
427             if(target->chan == support || !((support && isUserOnChan(target->user, support)) || (public && isUserOnChan(target->user, public)))) {
428                 //free the user's support request
429                 if(prev_helpnode)
430                     prev_helpnode->next = helpnode->next;
431                 else
432                     client->botclass_helpnode = helpnode->next;
433                 destroy_support_request(client, helpnode, 1);
434             }
435         }
436     }
437 }
438
439 static void neonhelp_event_part(struct ChanUser *target, char *reason) {
440     struct ClientSocket *client;
441     MYSQL_RES *res;
442     MYSQL_ROW row;
443     struct ChanNode *support, *public;
444     int userHasRequest;
445     for(client = getBots(SOCKET_FLAG_READY, NULL); client; client = getBots(SOCKET_FLAG_READY, client)) {
446         if(client->botid == BOTID && isUserOnChan(client->user, target->chan)) {
447             userHasRequest = 0;
448             struct NeonHelpNode *helpnode, *prev_helpnode = NULL;
449             if(client->flags & SOCKET_HAVE_HELPNODE) {
450                 for(helpnode = client->botclass_helpnode; helpnode; helpnode = helpnode->next) {
451                     if(helpnode->user == target->user) {
452                         userHasRequest = 1;
453                         break;
454                     } else
455                         prev_helpnode = helpnode;
456                 }
457             }
458             if(!userHasRequest) continue;
459             printf_mysql_query("SELECT `helpserv_support`, `helpserv_public`, `helpserv_intern` FROM `helpserv_settings` WHERE `helpserv_botid` = '%d'", client->clientid);
460             res = mysql_use();
461             if (!(row = mysql_fetch_row(res))) continue;
462             support = getChanByName(row[0]);
463             public = (row[1] ? getChanByName(row[1]) : NULL);
464             if(target->chan == support || !((support && isUserOnChan(target->user, support)) || (public && isUserOnChan(target->user, public)))) {
465                 //free the user's support request
466                 if(prev_helpnode)
467                     prev_helpnode->next = helpnode->next;
468                 else
469                     client->botclass_helpnode = helpnode->next;
470                 destroy_support_request(client, helpnode, 1);
471             }
472         }
473     }
474 }
475
476 static void neonhelp_event_quit(struct UserNode *target, char *reason) {
477     struct ClientSocket *client;
478     int userHasRequest;
479     for(client = getBots(SOCKET_FLAG_READY, NULL); client; client = getBots(SOCKET_FLAG_READY, client)) {
480         if(client->botid == BOTID) {
481             userHasRequest = 0;
482             struct NeonHelpNode *helpnode, *prev_helpnode = NULL;
483             if(client->flags & SOCKET_HAVE_HELPNODE) {
484                 for(helpnode = client->botclass_helpnode; helpnode; helpnode = helpnode->next) {
485                     if(helpnode->user == target) {
486                         userHasRequest = 1;
487                         break;
488                     } else
489                         prev_helpnode = helpnode;
490                 }
491             }
492             if(!userHasRequest) continue;
493             //free the user's support request
494             if(prev_helpnode)
495                 prev_helpnode->next = helpnode->next;
496             else
497                 client->botclass_helpnode = helpnode->next;
498             destroy_support_request(client, helpnode, 0);
499         }
500     }
501 }
502
503 void init_NeonHelp() {
504     
505     set_bot_alias(BOTID, BOTALIAS);
506     start_bots();
507     
508     //register events
509     bind_bot_ready(neonhelp_bot_ready);
510     bind_privmsg(neonhelp_event_privmsg);
511     bind_chanmsg(neonhelp_event_chanmsg);
512     bind_part(neonhelp_event_part);
513     bind_kick(neonhelp_event_kick);
514     bind_quit(neonhelp_event_quit);
515     
516     set_trigger_callback(BOTID, neonhelp_trigger_callback);
517     
518     register_default_language_table(msgtab);
519 }
520
521 void loop_NeonHelp() {
522     
523 }
524
525 void free_NeonHelp() {
526     
527 }
528
529 #undef BOTID
530 #undef BOTALIAS