added zero_bots_bot_ready function to autojoin zero bot channels on startup
authorpk910 <philipp@zoelle1.de>
Sun, 8 Jul 2012 14:35:56 +0000 (16:35 +0200)
committerpk910 <philipp@zoelle1.de>
Sun, 8 Jul 2012 14:35:56 +0000 (16:35 +0200)
src/bots.c

index 1fe8cea4ff1b94aeefa6f218662d9cc0f220322d..f1bfea843a4b777fe1a8ca91f9915539c79a40ff 100644 (file)
@@ -92,10 +92,34 @@ static void zero_bots_trigger_callback(int clientid, struct ChanNode *chan, char
         strcpy(trigger, ((row[1] && *row[1]) ? row[1] : "+"));
 }
 
+static void zero_bots_bot_ready(struct ClientSocket *client) {
+    if(client->botid != 0)
+        return;
+    MYSQL_RES *res;
+    MYSQL_ROW row;
+    
+    printf_mysql_query("SELECT `automodes`, `oper_user`, `oper_pass` FROM `bots` WHERE `id` = '%d'", client->clientid);
+    res = mysql_use();
+    if ((row = mysql_fetch_row(res)) != NULL) {
+        if(row[1] && row[2]) {
+            putsock(client, "OPER %s %s", row[1], row[2]);
+        }
+        putsock(client, "MODE %s +%s", client->user->nick, row[0]);
+    }
+    
+    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);
+    res = mysql_use();
+    
+    while ((row = mysql_fetch_row(res)) != NULL) {
+        putsock(client, "JOIN %s %s", row[0], row[1]);
+    }
+}
+
 void init_bots() {
     set_bot_alias(0, "0");
     start_zero_bots();
     set_trigger_callback(0, 0, zero_bots_trigger_callback);
+       bind_bot_ready(zero_bots_bot_ready, 0);
     
     MYSQL_RES *res;
     MYSQL_ROW row;