Преглед изворни кода

* Add command 'groups' to list all groups and which bots are in them.

Bryan Drewery пре 14 година
родитељ
комит
e09ce22591
5 измењених фајлова са 60 додато и 3 уклоњено
  1. 1 0
      doc/UPDATES
  2. 8 3
      doc/help.txt
  3. 45 0
      src/cmds.c
  4. 5 0
      src/set.c
  5. 1 0
      src/set.h

+ 1 - 0
doc/UPDATES

@@ -2,6 +2,7 @@
 * 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'
 * '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.
 
 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.

+ 8 - 3
doc/help.txt

@@ -294,7 +294,7 @@ See also: netnick, nick
    Specifying a nodename will display all bots up/down on that nodename.
    Bots with a * preceeding its name is down.
  
-See also: downbots%{+n}, bottree%{-}
+See also: groups, downbots%{+n}, bottree%{-}
 :hub:botserver:
 ###  $bbotserver$b <bot>
    The bot will display its current server and lag over DCC.
@@ -325,7 +325,7 @@ See also: set
    Red: localhubs (first bot in binary, see '%dhelp conf')
    Other: normal leaf bots
  
-See also: bots, downbots
+See also: bots, downbots, groups
 ::botversion:
 ###  $bbotversion$b <bot>
    The bot will display its pack version and uname.
@@ -955,7 +955,7 @@ See also: cycle
    Example:
       Down bots: cEvin, ruthie, Killa1
  
-See also: bots
+See also: bots, groups
 :leaf:dump
 ###  $bdump$b <text>
    dumps the text to the server.  keep in mind that this bot doesn't
@@ -1052,6 +1052,11 @@ See also: -exempt, +exempt, console%{+m|m}, chanset, chaninfo%{-}, stick, unstic
    specified, your console channel is used.
  
 See also: console, channels%{+m}, status%{-}
+:hub:groups
+###  $bgroups$b
+   Shows the list of groups and which bots are in them.
+ 
+See also: bots, downbots%{+n}, bottree%{-}
 ::handle
 ###  $bhandle$b <new-handle>
    Changes your handle on the bot. This is the handle (nickname) that the

+ 45 - 0
src/cmds.c

@@ -901,6 +901,50 @@ static void cmd_userlist(int idx, char *par)
   return;
 }
 
+static void cmd_groups(int idx, char *par)
+{
+  struct userrec *u = NULL;
+
+  putlog(LOG_CMDS, "*", "#%s# groups", dcc[idx].nick);
+
+  bd::Array<bd::String> globalgroups = bd::String(var_get_gdata("groups")).split(",");
+  bd::Array<bd::String> allgroups;
+  bd::HashTable<bd::String, bd::Array<bd::String> > groupBots;
+  bd::HashTable<bd::String, bd::Array<bd::String> > botGroups;
+  size_t maxGroupLen = 0;
+
+  // Need to loop over every bot and make a list of all groups and bots which are in those groups
+  for (u = userlist; u; u = u->next) {
+    if (u->bot && bot_hublevel(u) == 999) {
+      // Gather all the groups for this bot
+      botGroups[u->handle] = bd::String(var_get_bot_data(u, "groups", true)).split(",");
+      for (size_t i = 0; i < botGroups[u->handle].length(); ++i) {
+        const bd::String group(botGroups[u->handle][i]);
+        if (group.length() > maxGroupLen) {
+          maxGroupLen = group.length();
+        }
+        // Add their groups into the master list
+        if (allgroups.find(group) == allgroups.npos) {
+          allgroups << group;
+        }
+        // Add them to the list for this group
+        groupBots[group] << u->handle;
+
+      }
+    }
+  }
+
+  // Display all groups and which bots are in them
+  for (size_t i = 0; i < allgroups.length(); ++i) {
+    const bd::String group(allgroups[i]);
+    const bd::Array<bd::String> bots(groupBots[group]);
+    dumplots(idx, bd::String::printf("%-*s: ", int(maxGroupLen), group.c_str()).c_str(), static_cast<bd::String>(bots.join(" ")).c_str());
+  }
+
+  dprintf(idx, "Total groups: %zu\n", allgroups.length());
+  return;
+}
+
 static void cmd_channels(int idx, char *par) {
   putlog(LOG_CMDS, "*", "#%s# channels %s", dcc[idx].nick, par);
   if (par[0] && (dcc[idx].user->flags & USER_MASTER)) {
@@ -4666,6 +4710,7 @@ cmd_t C_dcc[] =
   {"version", 		"o", 	(Function) cmd_version, 	NULL, 0},
   {"netversion", 	"o", 	(Function) cmd_netversion, 	NULL, HUB},
   {"userlist", 		"m", 	(Function) cmd_userlist, 	NULL, 0},
+  {"groups", 		"m", 	(Function) cmd_groups, 		NULL, HUB},
   {"ps", 		"n", 	(Function) cmd_ps, 		NULL, 0},
   {"last", 		"n", 	(Function) cmd_last, 		NULL, 0},
   {"exec", 		"a", 	(Function) cmd_exec, 		NULL, 0},

+ 5 - 0
src/set.c

@@ -528,6 +528,11 @@ static inline variable_t *var_get_var_by_name(const char *name)
   return (variable_t*) bsearch(&key, &vars, lengthof(vars) - 1, sizeof(variable_t), comp_variable_t);
 }
 
+const char *var_get_gdata(const char *name) {
+  variable_t* var = var_get_var_by_name(name);
+  return var && var->gdata ? var->gdata : NULL;
+}
+
 void var_set(variable_t *var, const char *target, const char *datain)
 {
   /* Don't set locally if the variable doesn't permit it. */

+ 1 - 0
src/set.h

@@ -87,6 +87,7 @@ 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, bool useDefault = false);
+const char *var_get_gdata(const char *name);
 int cmd_set_real(const char *, int idx, char *);
 const char *var_get_str_by_name(const char *);