ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/modules/chanserv/list.C
Revision: 1.9
Committed: Sat Sep 22 14:27:27 2007 UTC (16 years, 8 months ago) by pippijn
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.8: +3 -3 lines
Log Message:
split up ermyth into ermyth-modules, libermyth (currently just ermyth-util) and ermyth-core

File Contents

# Content
1 /**
2 * list.C: This file contains code for the ChanServ LIST function.
3 *
4 * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team
5 * Rights to this code are as documented in COPYING.
6 *
7 *
8 * Portions of this file were derived from sources bearing the following license:
9 * Copyright © 2005 Robin Burchell, et al.
10 * Rights to this code are as documented in doc/pod/license.pod.
11 *
12 * $Id: list.C,v 1.8 2007-09-16 18:54:43 pippijn Exp $
13 */
14
15 #include <boost/foreach.hpp>
16
17 #include "atheme.h"
18 #include <ermyth/module.h>
19 #include <account/myuser.h>
20 #include <account/mychan.h>
21
22 static char const rcsid[] = "$Id: list.C,v 1.8 2007-09-16 18:54:43 pippijn Exp $";
23
24 REGISTER_MODULE ("chanserv/list", false, "The Ermyth Team <http://ermyth.xinutec.org>");
25
26 static void cs_cmd_list (sourceinfo_t *si, int parc, char *parv[]);
27
28 command_t const cs_list = { "LIST", N_("Lists channels registered matching a given pattern."), PRIV_CHAN_AUSPEX, 1, cs_cmd_list };
29
30 E cmdvec cs_cmdtree;
31 E helpvec cs_helptree;
32
33 bool
34 _modinit (module *m)
35 {
36 cs_cmdtree << cs_list;
37 help_addentry (cs_helptree, "LIST", "help/chanserv/list", NULL);
38
39 return true;
40 }
41
42 void
43 _moddeinit ()
44 {
45 cs_cmdtree >> cs_list;
46 help_delentry (cs_helptree, "LIST");
47 }
48
49 static void
50 cs_cmd_list (sourceinfo_t *si, int parc, char *parv[])
51 {
52 mychan_t *mc;
53 char *chanpattern = parv[0];
54 char buf[BUFSIZE];
55 unsigned int matches = 0;
56
57 if (!chanpattern)
58 {
59 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "LIST");
60 command_fail (si, fault::needmoreparams, _("Syntax: LIST <channel pattern>"));
61 return;
62 }
63
64 snoop ("LIST:CHANNELS: \2%s\2 by \2%s\2", chanpattern, get_oper_name (si));
65 command_success_nodata (si, _("Channels matching pattern \2%s\2:"), chanpattern);
66
67 foreach (mychan_t::pair_type &mp, mychan_t::map)
68 {
69 mc = mp.second;
70 if (!match (chanpattern, mc->name))
71 {
72 /* in the future we could add a LIMIT parameter */
73 *buf = '\0';
74
75 if (mc->find_metadata ("private:mark:setter"))
76 strlcat (buf, "\2[marked]\2", BUFSIZE);
77 if (mc->find_metadata ("private:close:closer"))
78 {
79 if (*buf)
80 strlcat (buf, " ", BUFSIZE);
81
82 strlcat (buf, "\2[closed]\2", BUFSIZE);
83 }
84 if (mc->flags & MC_HOLD)
85 {
86 if (*buf)
87 strlcat (buf, " ", BUFSIZE);
88
89 strlcat (buf, "\2[held]\2", BUFSIZE);
90 }
91
92 command_success_nodata (si, "- %s (%s) %s", mc->name, mc->founder_names (), buf);
93 matches++;
94 }
95 }
96
97 logcommand (si, CMDLOG_ADMIN, "LIST %s (%d matches)", chanpattern, matches);
98 if (matches == 0)
99 command_success_nodata (si, _("No channel matched pattern \2%s\2"), chanpattern);
100 else
101 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, chanpattern);
102 }