Sfoglia il codice sorgente

* Support group in cmd_channels

Bryan Drewery 14 anni fa
parent
commit
1646deec37
4 ha cambiato i file con 57 aggiunte e 36 eliminazioni
  1. 1 0
      doc/UPDATES
  2. 3 2
      doc/help.txt
  3. 9 7
      src/cmds.c
  4. 44 27
      src/misc.c

+ 1 - 0
doc/UPDATES

@@ -3,6 +3,7 @@
 * 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.
 
 
 1.4.0 - http://wraith.botpack.net/milestone/1.4.0
 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.
   * Updated server list, 'set -yes servers -' and 'set -yes servers6 -' to get new list.

+ 3 - 2
doc/help.txt

@@ -583,13 +583,14 @@ See also: %{-}%{+n}+chan, -chan%{-}%{+m|m}, chanset%{-}
  
  
 See also: status, whois
 See also: status, whois
 ::channels:
 ::channels:
-###  $bchannels$b %{+m}[user]%{-}
+###  $bchannels$b %{+m}[user|%group]%{-}
    Displays channels that you have access to, and any important 
    Displays channels that you have access to, and any important 
    flags that are set on them.
    flags that are set on them.
 %{+m}
 %{+m}
    Masters: You can specify other users to see what channels their 
    Masters: You can specify other users to see what channels their 
             flags grant them access to.%{-}
             flags grant them access to.%{-}
-See also: whois%{+m}, chattr, chaninfo%{-}
+   Special %%group to see what channels a particular group is in.
+See also: whois%{+m}, chattr, chaninfo, groups%{-}
 ::chanset
 ::chanset
 ###  $bchanset$b [#&!+channel|*|default] <settings>
 ###  $bchanset$b [#&!+channel|*|default] <settings>
    Allows you to change the channel settings (see $b'chaninfo'$b for the
    Allows you to change the channel settings (see $b'chaninfo'$b for the

+ 9 - 7
src/cmds.c

@@ -948,20 +948,22 @@ static void cmd_groups(int idx, char *par)
 static void cmd_channels(int idx, char *par) {
 static void cmd_channels(int idx, char *par) {
   putlog(LOG_CMDS, "*", "#%s# channels %s", dcc[idx].nick, par);
   putlog(LOG_CMDS, "*", "#%s# channels %s", dcc[idx].nick, par);
   if (par[0] && (dcc[idx].user->flags & USER_MASTER)) {
   if (par[0] && (dcc[idx].user->flags & USER_MASTER)) {
-    struct userrec *user = NULL;
-
-    user = get_user_by_handle(userlist, par);
-    if (user && whois_access(dcc[idx].user, user)) {
+    if (par[0] == '%') {
       show_channels(idx, par);
       show_channels(idx, par);
-    } else  {
-      dprintf(idx, "No such user.\n");
+    } else {
+      struct userrec *user = get_user_by_handle(userlist, par);
+      if (user && whois_access(dcc[idx].user, user)) {
+        show_channels(idx, par);
+      } else  {
+        dprintf(idx, "No such user.\n");
+      }
     }
     }
   } else {
   } else {
       show_channels(idx, NULL);
       show_channels(idx, NULL);
   }
   }
 
 
   if ((dcc[idx].user->flags & USER_MASTER) && !(par && par[0]))
   if ((dcc[idx].user->flags & USER_MASTER) && !(par && par[0]))
-    dprintf(idx, "You can also %schannels <user>\n", (dcc[idx].u.chat->channel >= 0) ? settings.dcc_prefix : "");
+    dprintf(idx, "You can also %schannels <user|%%group>\n", (dcc[idx].u.chat->channel >= 0) ? settings.dcc_prefix : "");
 }
 }
 
 
 
 

+ 44 - 27
src/misc.c

@@ -431,45 +431,62 @@ void show_motd(int idx)
 
 
 void show_channels(int idx, char *handle)
 void show_channels(int idx, char *handle)
 {
 {
-  struct chanset_t *chan = NULL;
-  struct flag_record fr = { FR_CHAN | FR_GLOBAL, 0, 0, 0 };
   struct userrec *u = NULL;
   struct userrec *u = NULL;
-  int first = 0, total = 0;
-  size_t l = 0;
-  char format[120] = "";
+  size_t maxChannelLength = 0;
+  bd::Array<bd::String> channelNames;
+  bd::HashTable<bd::String, struct chanset_t*> channels;
+  bd::String group;
 
 
-  if (handle)
+  if (handle && handle[0] != '%') {
     u = get_user_by_handle(userlist, handle);
     u = get_user_by_handle(userlist, handle);
-  else
+  } else {
     u = dcc[idx].user;
     u = dcc[idx].user;
+    if (handle && handle[0] == '%') {
+      group = handle + 1;
+    }
+  }
 
 
-  for (chan = chanset;chan ;chan = chan->next) {
+  for (struct chanset_t* chan = chanset; chan; chan = chan->next) {
+    struct flag_record fr = { FR_CHAN | FR_GLOBAL, 0, 0, 0 };
+    const bd::String chname(chan->dname);
+    // If a group was passed, ensure it matches
+    if (group.length() && chan->groups->find(group) == chan->groups->npos) {
+      continue;
+    }
     get_user_flagrec(u, &fr, chan->dname);
     get_user_flagrec(u, &fr, chan->dname);
-    if (l < strlen(chan->dname)) {
-      l = strlen(chan->dname);
+    if (group.length() || real_chk_op(fr, chan, 0)) {
+      if (maxChannelLength < chname.length()) {
+        maxChannelLength = chname.length();
+      }
+      channelNames << chname;
+      channels[chname] = chan;
     }
     }
-    if (real_chk_op(fr, chan, 0))
-      total++;
   }
   }
 
 
-  simple_snprintf(format, sizeof(format), "  %%c%%-%zus %%-s%%-s%%-s%%-s%%-s%%-s\n", (l+2));
+  if (channelNames.length()) {
+    char format[120] = "";
+    simple_snprintf(format, sizeof(format), "  %%c%%-%zus %%-s%%-s%%-s%%-s%%-s%%-s\n", (maxChannelLength+2));
+    if (group.length()) {
+      dprintf(idx, "group '%s' is in %zu channel%s:\n", group.c_str(), channelNames.length(), (channelNames.length() > 1) ? "s" : "");
+    } else {
+      dprintf(idx, "%s %s access to %zu channel%s:\n", handle ? u->handle : "You", handle ? "has" : "have", channelNames.length(), (channelNames.length() > 1) ? "s" : "");
+    }
 
 
-  for (chan = chanset;chan;chan = chan->next) {
-    get_user_flagrec(u, &fr, chan->dname);
-    if (real_chk_op(fr, chan, 0)) {
-        if (!first) { 
-          dprintf(idx, "%s %s access to %d channel%s:\n", handle ? u->handle : "You", handle ? "has" : "have", total, (total > 1) ? "s" : "");
-          
-          first = 1;
-        }
-        dprintf(idx, format, !conf.bot->hub && me_op(chan) ? '@' : ' ', chan->dname, !shouldjoin(chan) ? "(inactive) " : "", 
-           channel_privchan(chan) ? "(private)  " : "", chan->manop ? "(no manop) " : "", 
-           channel_bitch(chan) && !channel_botbitch(chan) ? "(bitch)    " : channel_botbitch(chan) ? "(botbitch) " : "",
-           channel_closed(chan) ?  "(closed) " : "", channel_backup(chan) ? "(backup)" : "");
+    for (size_t i = 0; i < channelNames.length(); ++i) {
+      const bd::String chname(channelNames[i]);
+      const struct chanset_t* chan = channels[chname];
+      dprintf(idx, format, !conf.bot->hub && me_op(chan) ? '@' : ' ', chan->dname, !shouldjoin(chan) ? "(inactive) " : "", 
+          channel_privchan(chan) ? "(private)  " : "", chan->manop ? "(no manop) " : "", 
+          channel_bitch(chan) && !channel_botbitch(chan) ? "(bitch)    " : channel_botbitch(chan) ? "(botbitch) " : "",
+          channel_closed(chan) ?  "(closed) " : "", channel_backup(chan) ? "(backup)" : "");
+    }
+  } else {
+    if (group.length()) {
+      dprintf(idx, "No channels found for group '%s'\n", group.c_str());
+    } else {
+      dprintf(idx, "%s %s not have access to any channels.\n", handle ? u->handle : "You", handle ? "does" : "do");
     }
     }
   }
   }
-  if (!first)
-    dprintf(idx, "%s %s not have access to any channels.\n", handle ? u->handle : "You", handle ? "does" : "do");
 }
 }
 
 
 /* Create a string with random letters and digits
 /* Create a string with random letters and digits