added auto-rejoin on kick to bot_NeonSpam.c
authorpk910 <philipp@zoelle1.de>
Tue, 29 Nov 2011 23:25:42 +0000 (00:25 +0100)
committerpk910 <philipp@zoelle1.de>
Tue, 29 Nov 2011 23:25:42 +0000 (00:25 +0100)
src/bot_NeonSpam.c

index 33e9cbf1ecb9d3bd7a5f6e4feec4b40f3306c3b1..056a82e9d7a4980c4a6edc720dba5f8b0fabefaa 100644 (file)
@@ -89,6 +89,31 @@ static struct NeonSpamJoinNode *getNeonSpamJoinNode(struct ChanUser *chanuser);
 #include "event_neonspam_join.c"
 #include "event_neonspam_chanmsg.c"
 
+static void neonspam_event_kick(struct UserNode *user, struct ChanUser *target, char *reason) {
+    struct ChanNode *chan = target->chan;
+    if(isBot(target->user)) {
+        struct ClientSocket *client = getChannelBot(chan, 0);
+        struct ClientSocket *bot = client;
+        for(client = getBots(SOCKET_FLAG_READY, NULL); client; client = getBots(SOCKET_FLAG_READY, client)) {
+            if(client->user == target->user) {
+                break;
+            }
+        }
+        if(!client) return;
+        if(bot && bot != client && (isModeSet(chan->modes, 'i') || isModeSet(chan->modes, 'a') || isModeSet(chan->modes, 'l'))) {
+            struct ChanUser *chanuser = getChanUser(bot->user, chan);
+            if(chanuser && chanuser->flags & CHANUSERFLAG_OPPED)
+                putsock(bot, "INVITE %s %s", target->user->nick, chan->name);
+        }
+        char *key = "";
+        if(isModeSet(chan->modes, 'k')) {
+            key = getModeValue(chan->modes, 'k');
+        }
+        putsock(client, "JOIN %s %s", chan->name, key);
+        return;
+    }
+}
+
 static void neonspam_bot_ready(struct ClientSocket *client) {
     MYSQL_RES *res;
     MYSQL_ROW row;
@@ -295,6 +320,7 @@ void init_NeonSpam() {
     bind_join(neonspam_event_join);
     bind_chanmsg(neonspam_event_chanmsg);
     bind_privctcp(general_event_privctcp);
+    bind_kick(neonspam_event_kick);
     
     set_trigger_callback(BOTID, neonspam_trigger_callback);