|
|
@@ -901,23 +901,69 @@ 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)) {
|
|
|
- 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);
|
|
|
- } 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 {
|
|
|
show_channels(idx, NULL);
|
|
|
}
|
|
|
|
|
|
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 : "");
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -1389,7 +1435,7 @@ static void cmd_botcmd(int idx, char *par)
|
|
|
continue;
|
|
|
cnt++;
|
|
|
bool group_match = false;
|
|
|
- if (botm[0] == '%') {
|
|
|
+ if (botm[0] == '%' && bot_hublevel(botu) == 999) {
|
|
|
bd::String botgroups = var_get_bot_data(botu, "groups", true);
|
|
|
if (botgroups.split(',').find(botm + 1) != bd::String::npos) {
|
|
|
group_match = true;
|
|
|
@@ -4729,6 +4775,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},
|