Ver Fonte

Modify format for 'botcmd %group' to support random leaf and localhubs (#36)

Bryan Drewery há 14 anos atrás
pai
commit
5cfe70b816
3 ficheiros alterados com 51 adições e 24 exclusões
  1. 1 1
      doc/UPDATES
  2. 1 1
      doc/help.txt
  3. 49 22
      src/cmds.c

+ 1 - 1
doc/UPDATES

@@ -23,7 +23,7 @@
   * Groups support added. See: http://wraith.botpack.net/wiki/Groups
   * Groups support added. See: http://wraith.botpack.net/wiki/Groups
     * Add [bot]set var 'groups' to configure what groups bots are in
     * 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 }'
     * 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'
+    * Added group support to 'botcmd': 'botcmd [*|&|?] %group cmd'
     * 'botjoin' and 'botpart' have been removed. Just use .+chan, .chanset, .botset to control groups.
     * 'botjoin' and 'botpart' have been removed. Just use .+chan, .chanset, .botset to control groups.
     * Add command 'groups' to list all groups and which bots are in them.
     * Add command 'groups' to list all groups and which bots are in them.
     * Command 'channels' now accepts a '%group' param to show which channels a group are in.
     * Command 'channels' now accepts a '%group' param to show which channels a group are in.

+ 1 - 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
    one. You can also specify a bot, and attempt to boot someone from another
    bot on the botnet. You cannot boot a bot owner.
    bot on the botnet. You cannot boot a bot owner.
 :hub:botcmd:
 :hub:botcmd:
-###  $bbotcmd$b <bot|*|?|&|%%group> <cmd> [params]
+###  $bbotcmd$b <bot|*|?|&> [%%group] <cmd> [params]
    The specified cmd and optional parameters are executed on the specified bot, 
    The specified cmd and optional parameters are executed on the specified bot, 
    all results are displayed back on DCC. For example:
    all results are displayed back on DCC. For example:
      [19:29] #bryan# botcmd wtest whom ...
      [19:29] #bryan# botcmd wtest whom ...

+ 49 - 22
src/cmds.c

@@ -1390,18 +1390,27 @@ static void cmd_botcmd(int idx, char *par)
     return;
     return;
   }
   }
 
 
-  char *botm = newsplit(&par), *cmd = NULL;
+  char *botm = newsplit(&par), *group = NULL, *cmd = NULL;
   bool rand_leaf = 0, all_localhub = 0;
   bool rand_leaf = 0, all_localhub = 0;
   
   
-  if (par[0])
+  if (par[0]) {
+    // Group specified
+    if (par[0] == '%') {
+      group = newsplit(&par);
+      ++group;
+    }
+  }
+  if (par[0]) {
     cmd = newsplit(&par);
     cmd = newsplit(&par);
+  }
 
 
   if (!botm[0] || !cmd || (cmd && !cmd[0])) {
   if (!botm[0] || !cmd || (cmd && !cmd[0])) {
-    dprintf(idx, "Usage: botcmd <bot|*|?|&|%%group> <cmd> [params]\n");
+    dprintf(idx, "Usage: botcmd <bot|*|?|&> [%%group] <cmd> [params]\n");
     return;
     return;
   }
   }
 
 
   int cnt = 0, rleaf = -1, tbots = 0, found = 0;
   int cnt = 0, rleaf = -1, tbots = 0, found = 0;
+  bool group_match = false;
   tand_t *tbot = NULL;
   tand_t *tbot = NULL;
 
 
   /* the rest of the cmd will be logged remotely */
   /* the rest of the cmd will be logged remotely */
@@ -1424,8 +1433,17 @@ static void cmd_botcmd(int idx, char *par)
   if (!strcmp(botm, "?")) {
   if (!strcmp(botm, "?")) {
     rand_leaf = 1;
     rand_leaf = 1;
     for (tbot = tandbot; tbot; tbot = tbot->next) {
     for (tbot = tandbot; tbot; tbot = tbot->next) {
-      if (bot_hublevel(get_user_by_handle(userlist, tbot->bot)) == 999)
-        tbots++;
+      if (bot_hublevel(tbot->u) == 999) {
+        group_match = false;
+        if (group) {
+          group_match = bd::String(var_get_bot_data(tbot->u, "groups", true)).split(',').find(group) != bd::String::npos;
+        } else {
+          group_match = true;
+        }
+        if (group_match) {
+          tbots++;
+        }
+      }
     }
     }
     if (tbots)
     if (tbots)
       rleaf = 1 + randint(tbots);		/* 1 <--> tbots */
       rleaf = 1 + randint(tbots);		/* 1 <--> tbots */
@@ -1439,29 +1457,38 @@ static void cmd_botcmd(int idx, char *par)
     }
     }
     all_localhub = 1;
     all_localhub = 1;
     for (tbot = tandbot; tbot; tbot = tbot->next) {
     for (tbot = tandbot; tbot; tbot = tbot->next) {
-      if (bot_hublevel(get_user_by_handle(userlist, tbot->bot)) == 999 && tbot->localhub)
-        tbots++;
+      if (bot_hublevel(tbot->u) == 999 && tbot->localhub) {
+        group_match = false;
+        if (group) {
+          group_match = bd::String(var_get_bot_data(tbot->u, "groups", true)).split(',').find(group) != bd::String::npos;
+        } else {
+          group_match = true;
+        }
+        if (group_match) {
+          tbots++;
+        }
+      }
     }
     }
   }
   }
   
   
   for (tbot = tandbot; tbot; tbot = tbot->next) {
   for (tbot = tandbot; tbot; tbot = tbot->next) {
-    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)))
+    if ((rand_leaf && bot_hublevel(tbot->u) != 999) ||
+        (all_localhub && (bot_hublevel(tbot->u) != 999 || !tbot->localhub)))
       continue;
       continue;
-    cnt++;
-    bool group_match = false;
-    if (botm[0] == '%' && bot_hublevel(botu) == 999) {
-      bd::String botgroups = var_get_bot_data(botu, "groups", true);
-      if (botgroups.split(',').find(botm + 1) != bd::String::npos) {
-        group_match = true;
-      }
+    group_match = false;
+    if (group && bot_hublevel(tbot->u) == 999) {
+      group_match = bd::String(var_get_bot_data(tbot->u, "groups", true)).split(',').find(group) != bd::String::npos;
+    } else if (!group) {
+      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 *) "");
-      found++;
+    if (group_match) {
+      cnt++;
+      if ((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 *) "");
+        found++;
+      }
     }
     }
   }
   }