Kaynağa Gözat

Merge branch 'groups-fixes'

* groups-fixes:
  * Update docs
  * Show total groups when matching on a bot
  * Only allow bots to be passed to cmd_groups
  * Check that bot is valid in cmd_groups
  * Fix hub showing itself as down
  * Fix wrong count when using filtered cmd_groups
Bryan Drewery 14 yıl önce
ebeveyn
işleme
86709c696f
5 değiştirilmiş dosya ile 24 ekleme ve 14 silme
  1. 8 7
      doc/UPDATES
  2. 1 1
      src/botnet.c
  3. 12 1
      src/cmds.c
  4. 2 4
      src/userrec.c
  5. 1 1
      src/users.h

+ 8 - 7
doc/UPDATES

@@ -18,13 +18,14 @@
   * Add cmd_newhub for adding a new hub. All bots will add this to their config.
   * Hubs can now be overridden inside the botconfig (-C)
   * Optimize userfile writing by doing it asynchronously
-  * 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'
-  * '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.
-  * Command 'channels' now accepts a '%group' param to show which channels a group are in.
-  * Add '%group' support to 'bots' command.
+  * Groups support added. See: http://wraith.botpack.net/wiki/Groups
+    * 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'
+    * '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.
+    * Command 'channels' now accepts a '%group' param to show which channels a group are in.
+    * Add '%group' support to 'bots' command.
   * Improve output of 'bots' command by displaying and sorting nodename
 
 maint

+ 1 - 1
src/botnet.c

@@ -582,7 +582,7 @@ tell_bots(int idx, int up, const char *nodename)
       const char *userNode = (const char*) get_user(&USERENTRY_NODENAME, u);
       const bd::String node(userNode ? userNode : "(unknown)");
       const bool node_match = ((nodename && node.length() && wild_match(nodename, node.c_str())) || !nodename);
-      const bool bot_found = findbot(u->handle);
+      const bool bot_found = u == conf.bot->u || findbot(u->handle);
       const bool up_down_match = (nodename || (!nodename && ((up && bot_found) || (!up && !bot_found))));
       if (group_match || (group.length() == 0 && node_match && up_down_match)) {
         if (nodes.find(node) == nodes.npos) {

+ 12 - 1
src/cmds.c

@@ -908,6 +908,16 @@ static void cmd_groups(int idx, char *par)
   putlog(LOG_CMDS, "*", "#%s# groups %s", dcc[idx].nick, par);
   bd::String botnick(newsplit(&par));
 
+  if (botnick.length() && !(u = get_user_by_handle(userlist, botnick.c_str()))) {
+    dprintf(idx, "No such bot.\n");
+    return;
+  }
+
+  if (u && !u->bot) {
+    dprintf(idx, "%s is not a bot.\n", botnick.c_str());
+    return;
+  }
+
   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;
@@ -937,6 +947,7 @@ static void cmd_groups(int idx, char *par)
 
   if (botnick.length()) {
     dprintf(idx, "%s is in groups: %s\n", botnick.c_str(), static_cast<bd::String>(botGroups[botnick].join(" ")).c_str());
+    dprintf(idx, "Total groups: %zu/%zu\n", botGroups[botnick].length(), allgroups.length());
   } else {
     // Display all groups and which bots are in them
     for (size_t i = 0; i < allgroups.length(); ++i) {
@@ -944,9 +955,9 @@ static void cmd_groups(int idx, char *par)
       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());
   }
 
-  dprintf(idx, "Total groups: %zu\n", allgroups.length());
   return;
 }
 

+ 2 - 4
src/userrec.c

@@ -77,7 +77,7 @@ int count_users(struct userrec *bu)
   return tot;
 }
 
-static struct userrec *check_dcclist_hand(char *handle)
+static struct userrec *check_dcclist_hand(const char *handle)
 {
   for (int i = 0; i < dcc_total; i++)
     if (dcc[i].type && !strcasecmp(dcc[i].nick, handle))
@@ -103,13 +103,11 @@ struct userrec *host_conflicts(char *host)
   return NULL;
 }
 
-struct userrec *get_user_by_handle(struct userrec *bu, char *handle)
+struct userrec *get_user_by_handle(struct userrec *bu, const char *handle)
 {
   if (!handle)
     return NULL;
 
-  /* FIXME: This should be done outside of this function. */
-  rmspace(handle);
   if (!handle[0] || (handle[0] == '*'))
     return NULL;
 

+ 1 - 1
src/users.h

@@ -147,7 +147,7 @@ extern struct igrec *global_ign;
  * Note: Flags are in eggdrop.h
  */
 
-struct userrec *get_user_by_handle(struct userrec *, char *);
+struct userrec *get_user_by_handle(struct userrec *, const char *);
 struct userrec *get_user_by_host(char *);
 struct userrec *check_chanlist(const char *);
 struct userrec *check_chanlist_hand(const char *);