Sfoglia il codice sorgente

* Only join if the bot's group matches

This also removes the previous assumption that a +backup chan should
join all bots. Now only B|B bots will join +backup channels.
Bryan Drewery 14 anni fa
parent
commit
2fd0cb0662
2 ha cambiato i file con 21 aggiunte e 3 eliminazioni
  1. 2 0
      doc/UPDATES
  2. 19 3
      src/chanprog.c

+ 2 - 0
doc/UPDATES

@@ -1,3 +1,5 @@
+* Add [bot]set var 'groups' to configure what groups bots are in
+
 1.4.0 - http://wraith.botpack.net/milestone/1.4.0
   * Updated server list, 'set -yes servers -' and 'set -yes servers6 -' to get new list.
   * Change +bitch reaction to use normal queue for deopping opper/opped clients

+ 19 - 3
src/chanprog.c

@@ -54,6 +54,8 @@
 #endif
 #endif
 #include <sys/utsname.h>
+#include <bdlib/src/Array.h>
+#include <bdlib/src/String.h>
 
 char *def_chanset = "+enforcebans +dynamicbans +userbans -bitch +cycle -inactive +userexempts -dynamicexempts +userinvites -dynamicinvites -nodesynch -closed -take -voice -private -fastop +meankicks ban-type 3 protect-backup 1";
 struct chanset_t 	*chanset = NULL;	/* Channel list			*/
@@ -857,10 +859,24 @@ bool bot_shouldjoin(struct userrec* u, struct flag_record* fr, struct chanset_t*
       return 0;
   }
 #endif
+
+  // Am I in the groups that this channel has?
+  bd::Array<bd::String> my_groupsArray(bd::String(groups).split(',')), channel_groupsArray(bd::String(chan->groups).split(' '));
+  bool group_match = 0;
+
+  for (size_t i = 0; i < my_groupsArray.length(); ++i) {
+    if (channel_groupsArray.find(my_groupsArray[i]) != channel_groupsArray.npos) {
+      group_match = 1;
+      break;
+    }
+  }
+
   // Ignore +inactive during cmd_slowjoin to ensure that +backup bots join
-  return (!glob_kick(*fr) && !chan_kick(*fr) &&
-      ((ignore_inactive || !channel_inactive(chan)) &&
-       (channel_backup(chan) || (!glob_backup(*fr) && !chan_backup(*fr)))));
+  return (!glob_kick(*fr) && !chan_kick(*fr) && // Not being kicked
+      ((ignore_inactive || !channel_inactive(chan)) && // Not inactive
+      ((channel_backup(chan) && (glob_backup(*fr) || chan_backup(*fr))) || (!channel_backup(chan) && !glob_backup(*fr) && !chan_backup(*fr)))) && // Is +backup and I'm B|B, or is -backup and I am not B|B
+      group_match // My group should join
+      );
 }
 
 bool shouldjoin(struct chanset_t *chan)