Explorar el Código

* cmd_botconfig now supports wildcards for the bot parameter

svn: 1785
Bryan Drewery hace 21 años
padre
commit
58b0a02ca1
Se han modificado 3 ficheros con 67 adiciones y 52 borrados
  1. 1 0
      doc/UPDATES
  2. 1 0
      misc/help.txt
  3. 65 52
      src/cmds.c

+ 1 - 0
doc/UPDATES

@@ -18,6 +18,7 @@ Lines prefixxed with '-' were disabled before release and are not finishsed.
 * Using a cmd with a cmdpass without proper flags now acts as if cmd is not valid (no longer spams wrong pass error)
 * cmd_deluser change: only allow a |m user to remove users whom they have added.
 * Fixed some botnet userfile sharing logs showing up on leaf bots.
+* cmd_botconfig now supports wildcards for the bot parameter
 
 1.2.2
 * Don't sanity check flags for users on DCC CHAT if they are on the bot via .botcmd.

+ 1 - 0
misc/help.txt

@@ -273,6 +273,7 @@ See also: bc, cmdpass
 :hub:botconfig:
 ###  $bbotconfig$b <bot> [name [value|-]]
    Set's a bot specific entry.
+   <bot> may contain wildcards.
    NOTE: 'config' and 'botconfig' have different entries. 
    If there is a botconfig entry for 'name' and a config entry for 'name', 
    the bot will use the 'botconfig' entry. Otherwise, the 'config' entry

+ 65 - 52
src/cmds.c

@@ -310,15 +310,18 @@ static void cmd_config(int idx, char *par)
 static void cmd_botconfig(int idx, char *par)
 {
   struct userrec *u2 = NULL;
-  char *p = NULL;
+  char *entry = NULL, *botm = NULL;
   struct xtra_key *k = NULL;
   struct cfg_entry *cfgent = NULL;
   int i, cnt;
+  tand_t *tbot = NULL;
+  bool found = 0, described = 0;
 
   /* botconfig bot [name [value]]  */
   putlog(LOG_CMDS, "*", "#%s# botconfig %s", dcc[idx].nick, par);
   if (!par[0]) {
-    dprintf(idx, "Usage: botconfig bot [name [value|-]]\n");
+    dprintf(idx, "Usage: botconfig <bot> [name [value|-]]\n");
+    dprintf(idx, " <bot> may contain wildcards\n");
     cnt = 0;
     for (i = 0; i < cfg_count; i++) {
       if (cfg[i]->flags & CFGF_LOCAL) {
@@ -334,60 +337,70 @@ static void cmd_botconfig(int idx, char *par)
       dprintf(idx, "\n");
     return;
   }
-  p = newsplit(&par);
-  u2 = get_user_by_handle(userlist, p);
-  if (!u2) {
-    dprintf(idx, "No such user.\n");
-    return;
-  }
-  if (!u2->bot) {
-    dprintf(idx, "%s isn't a bot.\n", p);
-    return;
-  }
-  if (!par[0]) {
-    for (i = 0; i < cfg_count; i++) {
-      if ((cfg[i]->flags & CFGF_LOCAL) && (cfg[i]->describe)) {
-	k = (struct xtra_key *) get_user(&USERENTRY_CONFIG, u2);
-	while (k && strcmp(k->key, cfg[i]->name))
-	  k=k->next;
-	if (k)
-	  dprintf(idx, "  %s: %s\n", k->key, k->data);
-	else
-	  dprintf(idx, "  %s: (not set)\n", cfg[i]->name);
+  botm = newsplit(&par);
+  entry = newsplit(&par);
+
+  for (tbot = tandbot; tbot; tbot = tbot->next) {
+    if (wild_match(botm, tbot->bot)) {
+      u2 = get_user_by_handle(userlist, tbot->bot);
+      if (!u2)
+        continue;
+
+      found = 1;
+
+      dprintf(idx, "%s:\n", tbot->bot);
+
+      if (!entry || !entry[0]) {
+        for (i = 0; i < cfg_count; i++) {
+          if ((cfg[i]->flags & CFGF_LOCAL) && (cfg[i]->describe)) {
+	    k = (struct xtra_key *) get_user(&USERENTRY_CONFIG, u2);
+            while (k && strcmp(k->key, cfg[i]->name))
+              k = k->next;
+            if (k)
+              dprintf(idx, "  %s: %s\n", k->key, k->data);
+            else
+              dprintf(idx, "  %s: (not set)\n", cfg[i]->name);
+          }
+        }
+        continue;
       }
-    }
-    return;
-  }
-  p = newsplit(&par);
-  cfgent = NULL;
-  for (i = 0; !cfgent && (i < cfg_count); i++)
-    if (!strcmp(cfg[i]->name, p) && (cfg[i]->flags & CFGF_LOCAL) && (cfg[i]->describe))
-      cfgent=cfg[i];
-  if (!cfgent) {
-    dprintf(idx, "No such configuration value\n");
-    return;
-  }
-  if (par[0]) {
-    char tmp[100] = "";
 
-    set_cfg_str(u2->handle, cfgent->name, (strcmp(par, "-")) ? par : NULL);
-    egg_snprintf(tmp, sizeof tmp, "%s %s", cfgent->name, par);
-    update_mod(u2->handle, dcc[idx].nick, "botconfig", tmp);
-    dprintf(idx, "Now: ");
+      cfgent = NULL;
+      for (i = 0; !cfgent && (i < cfg_count); i++)
+        if (!strcmp(cfg[i]->name, entry) && (cfg[i]->flags & CFGF_LOCAL) && (cfg[i]->describe))
+          cfgent = cfg[i];
+      if (!cfgent) {
+        dprintf(idx, "No such configuration value\n");
+        return;
+      }
+      if (par[0]) {
+        char tmp[100] = "";
+
+        set_cfg_str(u2->handle, cfgent->name, (strcmp(par, "-")) ? par : NULL);
+        egg_snprintf(tmp, sizeof tmp, "%s %s", cfgent->name, par);
+        update_mod(u2->handle, dcc[idx].nick, "botconfig", tmp);
+        dprintf(idx, "Now: ");
 #ifdef HUB
-    write_userfile(idx);
+        write_userfile(idx);
 #endif /* HUB */
-  } else {
-    if (cfgent->describe)
-      cfgent->describe(cfgent, idx);
-  }
-  k = (struct xtra_key *) get_user(&USERENTRY_CONFIG, u2);
-  while (k && strcmp(k->key, cfgent->name))
-    k = k->next;
-  if (k)
-    dprintf(idx, "  %s: %s\n", k->key, k->data);
-  else
-    dprintf(idx, "  %s: (not set)\n", cfgent->name);
+      } else {
+        if (cfgent->describe && !described) {
+          described++;
+          cfgent->describe(cfgent, idx);
+        }
+      }
+      k = (struct xtra_key *) get_user(&USERENTRY_CONFIG, u2);
+      while (k && strcmp(k->key, cfgent->name))
+        k = k->next;
+      if (k)
+        dprintf(idx, "  %s: %s\n", k->key, k->data);
+      else
+        dprintf(idx, "  %s: (not set)\n", cfgent->name);
+    }
+  }
+
+  if (!found)
+    dprintf(idx, "No bot matching '%s' linked\n", botm);
 }
 
 static void cmd_cmdpass(int idx, char *par)