Просмотр исходного кода

Merge branch '21-botgroups' (early part) into next

* '21-botgroups' (early part):
  * Fix groups not being 'main' if leaf had no local setting
  * Add botcmd support for groups
  * Update bdlib

Conflicts:
	doc/UPDATES
Bryan Drewery 14 лет назад
Родитель
Сommit
f48000be8c
6 измененных файлов с 27 добавлено и 10 удалено
  1. 1 0
      doc/UPDATES
  2. 2 1
      doc/help.txt
  3. 1 1
      src/chanprog.c
  4. 13 5
      src/cmds.c
  5. 9 2
      src/set.c
  6. 1 1
      src/set.h

+ 1 - 0
doc/UPDATES

@@ -3,6 +3,7 @@ next
   * Properly honor exemptions when kicking matched RBL clients
   * Add [bot]set var 'groups' to configure what groups bots are in
   * Add chanset 'groups' to take a list of groups that should join. 'chanset #chan groups { main backup }'
+  * Added group support to 'botcmd': 'botcmd %group cmd'
 
 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.

+ 2 - 1
doc/help.txt

@@ -235,7 +235,7 @@ See also: -ban, +ban, console%{+m|m}, chanset, chaninfo%{-}, stick, unstick
    one. You can also specify a bot, and attempt to boot someone from another
    bot on the botnet. You can not boot a bot owner.
 :hub:botcmd:
-###  $bbotcmd$b <bot> <cmd> [params]
+###  $bbotcmd$b <bot|*|?|&|%%group> <cmd> [params]
    The specified cmd and optional parameters are executed on the specified bot, 
    all results are displayed back on DCC. For example:
      [19:29] #bryan# botcmd wtest whom ...
@@ -253,6 +253,7 @@ See also: -ban, +ban, console%{+m|m}, chanset, chaninfo%{-}, stick, unstick
  
    Just using '?' for 'bot' will choose a random leaf bot.
    Just using '&' for 'bot' will do the cmd on all localhub bots. (first bot in config).
+   Use '%%group' to match a specific group. (see also: '%dhelp set')
  
    This cmd cannot be chained over the botnet, ie, no: '%dbotcmd [bot] botcmd [bot2] ...'
  

+ 1 - 1
src/chanprog.c

@@ -766,7 +766,7 @@ bool bot_shouldjoin(struct userrec* u, struct flag_record* fr, struct chanset_t*
 #endif
 
   // Is this bot in the groups that this channel has?
-  const char *botgroups = u == conf.bot->u ? groups : var_get_bot_data(u, "groups");
+  const char *botgroups = u == conf.bot->u ? groups : var_get_bot_data(u, "groups", true);
   bd::Array<bd::String> my_groupsArray(bd::String(botgroups).split(','));
   bool group_match = 0;
 

+ 13 - 5
src/cmds.c

@@ -1335,7 +1335,7 @@ static void cmd_botcmd(int idx, char *par)
     cmd = newsplit(&par);
 
   if (!botm[0] || !cmd || (cmd && !cmd[0])) {
-    dprintf(idx, "Usage: botcmd <bot> <cmd> [params]\n");
+    dprintf(idx, "Usage: botcmd <bot|*|?|&|%%group> <cmd> [params]\n");
     return;
   }
 
@@ -1347,7 +1347,7 @@ static void cmd_botcmd(int idx, char *par)
     putlog(LOG_CMDS, "*", "#%s# botcmd %s %s ...", dcc[idx].nick, botm, cmd);
 
   // Restrict dangerous mass commands ('botcmd *' (any *) or 'botcmd &')
-  if ((strchr(botm, '*') && !findbot(botm)) || !strcmp(botm, "&")) {
+  if ((strchr(botm, '*') && !findbot(botm)) || !strcmp(botm, "&") || botm[0] == '%') {
     if (!strncasecmp(cmd, "di", 2) || (!strncasecmp(cmd, "res", 3) && strncasecmp(cmd, "reset", 5)) || !strncasecmp(cmd, "sui", 3) || !strncasecmp(cmd, "pl", 2) || !strncasecmp(cmd, "ac", 2) ||
         !strncasecmp(cmd, "j", 1) || (!strncasecmp(cmd, "dump", 4) && (!strncasecmp(par, "privmsg", 7) || !strncasecmp(par, "notice", 6) || !strncasecmp(par, "quit", 4)))) {
       dprintf(idx, "Not a good idea.\n");
@@ -1383,11 +1383,19 @@ static void cmd_botcmd(int idx, char *par)
   }
   
   for (tbot = tandbot; tbot; tbot = tbot->next) {
-    if ((rand_leaf && bot_hublevel(get_user_by_handle(userlist, tbot->bot)) != 999) ||
-        (all_localhub && (bot_hublevel(get_user_by_handle(userlist, tbot->bot)) != 999 || !tbot->localhub)))
+    struct userrec *botu = get_user_by_handle(userlist, tbot->bot);
+    if ((rand_leaf && bot_hublevel(botu) != 999) ||
+        (all_localhub && (bot_hublevel(botu) != 999 || !tbot->localhub)))
       continue;
     cnt++;
-    if ((rleaf != -1 && cnt == rleaf) || (rleaf == -1 && (all_localhub || wild_match(botm, tbot->bot)))) {
+    bool group_match = false;
+    if (botm[0] == '%') {
+      bd::String botgroups = var_get_bot_data(botu, "groups", true);
+      if (botgroups.split(',').find(botm + 1) != bd::String::npos) {
+        group_match = true;
+      }
+    }
+    if (group_match || (rleaf != -1 && cnt == rleaf) || (rleaf == -1 && (all_localhub || wild_match(botm, tbot->bot)))) {
       if (rleaf != -1)
         putlog(LOG_CMDS, "*", "#%s# botcmd %s %s ...", dcc[idx].nick, tbot->bot, cmd);
       send_remote_simul(idx, tbot->bot, cmd, par ? par : (char *) "");

+ 9 - 2
src/set.c

@@ -699,7 +699,7 @@ void var_userfile_share_line(char *line, int idx, bool share)
     check_removed_server();
 }
 
-const char *var_get_bot_data(struct userrec *u, const char *name)
+const char *var_get_bot_data(struct userrec *u, const char *name, bool useDefault)
 {
   if (!u)
     return NULL;
@@ -710,7 +710,14 @@ const char *var_get_bot_data(struct userrec *u, const char *name)
   while (xk && strcmp(xk->key, name))
     xk = xk->next;
 
-  return xk ? xk->data : NULL;
+  if (xk) {
+    return xk->data;
+  }
+  if (useDefault) {
+    variable_t *var = var_get_var_by_name(name);
+    return var->def;
+  }
+  return NULL;
 }
 
 

+ 1 - 1
src/set.h

@@ -86,7 +86,7 @@ void var_parse_my_botset();
 void init_vars();
 void var_set_by_name(const char *, const char *, const char *);
 void var_set_userentry(const char *, const char *, const char *);
-const char *var_get_bot_data(struct userrec *u, const char *name);
+const char *var_get_bot_data(struct userrec *u, const char *name, bool useDefault = false);
 int cmd_set_real(const char *, int idx, char *);
 const char *var_get_str_by_name(const char *);