]> jfr.im git - irc/quakenet/newserv.git/blobdiff - qabot/qabot_bot.c
Merge pull request #2 from meeb/meeb
[irc/quakenet/newserv.git] / qabot / qabot_bot.c
index 1b6e209ee95ef39a3a80fa18c46b29cfed57edea..aa984da90428966698da045ebfe0af0e32d22804 100644 (file)
@@ -1,5 +1,4 @@
 #include <stdio.h>
-#include <string.h>
 #include <time.h>
 
 #include "../nick/nick.h"
@@ -49,12 +48,14 @@ qab_bot* qabot_getbot() {
   bot->answers = 0;
   
   bot->micnumeric = 0;
-  
-  bot->recording_section = 0;
-  bot->texts = 0;
+  bot->recnumeric = 0;
+  bot->recfile = NULL;
+  bot->playfile = NULL;
   
   bot->next = 0;
   bot->prev = 0;
+
+  return bot;
 }
 
 int qabot_addbot(char* nickname, char* user, char* host, char* pub_chan, char* qu_chan, char* stff_chan, flag_t flags, int spam_interval, 
@@ -189,9 +190,16 @@ void qabot_delbot(qab_bot* bot) {
   deleteschedule(0, qabot_createbotfakeuser, (void*)bot);
   deleteschedule(0, qabot_timer, (void*)bot);
   
-  while (bot->texts)
-    qabot_freetext(bot, texts);
-          
+  if (bot->recfile) {
+    fclose(bot->recfile);
+    bot->recfile = NULL;
+  }
+  
+  if (bot->playfile) {
+    fclose(bot->playfile);
+    bot->playfile = NULL;
+  }
+  
   while (bot->blocks) {
     b = bot->blocks;
     bot->blocks = bot->blocks->next;
@@ -237,6 +245,67 @@ void qabot_delbot(qab_bot* bot) {
   free(bot);
 }
 
+void qabot_playback(qab_bot *bot) {
+  char buf[1024];
+  unsigned long lines;
+  
+  if (!(bot->playfile)) {
+    return;
+  }
+  
+  lines = 0;
+  
+  while (!feof(bot->playfile)) {
+    fscanf(bot->playfile, "%[^\n]\n", buf);
+    
+    if (!ircd_strcmp("--PAUSE--", buf)) {
+      if (bot->staff_chan && bot->staff_chan->channel) { 
+        sendmessagetochannel(bot->np, bot->staff_chan->channel, "Pause found in playback, use !continue when ready to continue playback.");
+        sendmessagetochannel(bot->np, bot->staff_chan->channel, "%lu lines ready to send to channel. This will take approx. %sto send.", lines, longtoduration((lines * SPAMINTERVAL), 1));
+      }
+      
+      return;
+    }
+    
+    lines++;
+    
+    /* Copied from microphone code */
+    if (bot->lastspam) {
+      qab_spam* s;
+      
+      s = (qab_spam*)malloc(sizeof(qab_spam));
+      s->message = strdup(buf);
+      s->next = 0;
+      bot->lastspam->next = s;
+      bot->lastspam = s;
+    }
+    else {
+      if ((bot->spamtime + bot->spam_interval) < time(0)) {
+        sendmessagetochannel(bot->np, bot->public_chan->channel, "%s", buf);
+        bot->spammed++;
+        bot->spamtime = time(0);
+      }
+      else {
+        qab_spam* s;
+        
+        s = (qab_spam*)malloc(sizeof(qab_spam));
+        s->message = strdup(buf);
+        s->next = 0;
+        bot->nextspam = bot->lastspam = s;
+        scheduleoneshot(bot->spamtime + bot->spam_interval, qabot_spam, (void*)bot);
+      }
+    }
+  }
+  
+  fclose(bot->playfile);
+  bot->playfile = NULL;
+  
+  if (bot->staff_chan && bot->staff_chan->channel) { 
+    sendmessagetochannel(bot->np, bot->staff_chan->channel, "End of playback.");
+    sendmessagetochannel(bot->np, bot->staff_chan->channel, "%lu lines ready to send to channel. This will take approx. %sto send.", lines, longtoduration((lines * SPAMINTERVAL), 1));
+  }
+}
+
 void qabot_spam(void* arg) {
   qab_bot* bot = (qab_bot*)arg;
   qab_spam* s;
@@ -330,12 +399,9 @@ void qabot_timer(void* arg) {
   if (bot->micnumeric && (bot->mic_timeout > 0) && (time(NULL) >= (bot->lastmic + bot->mic_timeout))) {
     bot->micnumeric = 0;
     
-    sendmessagetochannel(bot->np, bot->staff_chan->channel, "%s deactivated (idle timeout).", 
-      bot->recording_section ? "Recorder" : "Mic");
-    if (!bot->lastspam && !bot->recording_section)
+    sendmessagetochannel(bot->np, bot->staff_chan->channel, "Mic deactivated (idle timeout).");
+    if (!bot->lastspam)
       qabot_spamstored((void*)bot);
-    
-    bot->recording_section = 0;
   }
   
   scheduleoneshot(time(NULL) + 10, &qabot_timer, (void*)bot);