Explorar el Código

cmds_bots: Sort the bot list for shell display

Bryan Drewery hace 7 años
padre
commit
fa45ed9fe1
Se han modificado 2 ficheros con 18 adiciones y 5 borrados
  1. 1 1
      doc/UPDATES.md
  2. 17 4
      src/botnet.cc

+ 1 - 1
doc/UPDATES.md

@@ -13,7 +13,7 @@
   * CPRIVMSG/CNOTICE/TIME/TOPIC/OPER should end connection bursting on ratbox.
   * Fix server connect bursting for joining channels with help from other bots.
   * Tweak server connect burst to progress quicker.
-  * Sort cmd_groups
+  * Sort cmd_groups and cmd_bots better.
 
 # maint
   * Clear FiSH keys when a client quits.

+ 17 - 4
src/botnet.cc

@@ -547,7 +547,17 @@ void answer_local_whom(int idx, int chan)
   dprintf(idx, "Total users: %d\n", total);
 }
 
-bool sortNodes(const bd::String nodeA, const bd::String nodeB) {
+static bool
+__attribute__((pure))
+sortDownBots(bd::String botA, bd::String botB) {
+  if (botA[0] == '*') ++botA;
+  if (botB[0] == '*') ++botB;
+  return botA < botB;
+}
+
+static bool
+__attribute__((pure))
+sortNodes(const bd::String& nodeA, const bd::String& nodeB) {
   const bd::String unknown("(unknown)");
   if (nodeA == unknown) {
     return true;
@@ -630,9 +640,12 @@ tell_bots(int idx, int up, const char *nodename)
   } else {
     // Sort by nodes
     std::sort(nodes.begin(), nodes.end(), sortNodes);
-    for (size_t i = 0; i < nodes.length(); ++i) {
-      const bd::String node(nodes[i]);
-      const bd::Array<bd::String> botsInNode(nodeBots[node]);
+    for (auto& kv : nodeBots) {
+      auto& botlist{kv.second};
+      std::sort(botlist.begin(), botlist.end(), sortDownBots);
+    }
+    for (const auto& node : nodes) {
+      const auto& botsInNode(nodeBots[node]);
       dumplots(idx,
           bd::String::printf("%*s: ",
             int(maxNodeNameLength), node.c_str()),