| 1 |
/* |
| 2 |
* Copyright (c) 2005 Atheme Development Group |
| 3 |
* Rights to this code are documented in doc/LICENSE. |
| 4 |
* |
| 5 |
* This file contains routines to handle the GroupServ HELP command. |
| 6 |
* |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "atheme.h" |
| 10 |
#include "groupserv.h" |
| 11 |
|
| 12 |
DECLARE_MODULE_V1 |
| 13 |
( |
| 14 |
"groupserv/list", false, _modinit, _moddeinit, |
| 15 |
PACKAGE_STRING, |
| 16 |
VENDOR_STRING |
| 17 |
); |
| 18 |
|
| 19 |
static void gs_cmd_list(sourceinfo_t *si, int parc, char *parv[]); |
| 20 |
|
| 21 |
command_t gs_list = { "LIST", N_("List registered groups."), PRIV_GROUP_AUSPEX, 1, gs_cmd_list, { .path = "groupserv/list" } }; |
| 22 |
|
| 23 |
/* Perhaps add criteria to groupser/list like there is now in chanserv/list and nickserv/list in the future */ |
| 24 |
static void gs_cmd_list(sourceinfo_t *si, int parc, char *parv[]) |
| 25 |
{ |
| 26 |
myentity_t *mt; |
| 27 |
char *pattern = parv[0]; |
| 28 |
unsigned int matches = 0; |
| 29 |
myentity_iteration_state_t state; |
| 30 |
|
| 31 |
if (!pattern) |
| 32 |
{ |
| 33 |
command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "LIST"); |
| 34 |
command_fail(si, fault_needmoreparams, _("Syntax: LIST <group pattern>")); |
| 35 |
return; |
| 36 |
} |
| 37 |
|
| 38 |
/* No need to say "Groups currently registered". You can't have a unregistered group. */ |
| 39 |
command_success_nodata(si, _("Groups matching pattern \2%s\2:"), pattern); |
| 40 |
|
| 41 |
MYENTITY_FOREACH_T(mt, &state, ENT_GROUP) |
| 42 |
{ |
| 43 |
mygroup_t *mg = group(mt); |
| 44 |
continue_if_fail(mt != NULL); |
| 45 |
continue_if_fail(mg != NULL); |
| 46 |
|
| 47 |
if (!match(pattern, entity(mg)->name)) |
| 48 |
{ |
| 49 |
command_success_nodata(si, _("- %s (%s)"), entity(mg)->name, mygroup_founder_names(mg)); |
| 50 |
matches++; |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
if (matches == 0) |
| 55 |
command_success_nodata(si, _("No groups matched pattern \2%s\2"), pattern); |
| 56 |
else |
| 57 |
command_success_nodata(si, ngettext(N_("\2%d\2 match for pattern \2%s\2"), N_("\2%d\2 matches for pattern \2%s\2"), matches), matches, pattern); |
| 58 |
|
| 59 |
logcommand(si, CMDLOG_ADMIN, "LIST: \2%s\2 (\2%d\2 matches)", pattern, matches); |
| 60 |
} |
| 61 |
|
| 62 |
void _modinit(module_t *m) |
| 63 |
{ |
| 64 |
use_groupserv_main_symbols(m); |
| 65 |
|
| 66 |
service_named_bind_command("groupserv", &gs_list); |
| 67 |
} |
| 68 |
|
| 69 |
void _moddeinit(module_unload_intent_t intent) |
| 70 |
{ |
| 71 |
service_named_unbind_command("groupserv", &gs_list); |
| 72 |
} |
| 73 |
|