ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/modules/chanserv/mark.C
Revision: 1.8
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.7: +5 -3 lines
Log Message:
split up ermyth into ermyth-modules, libermyth (currently just ermyth-util) and ermyth-core

File Contents

# Content
1 /**
2 * mark.C: Marking for channels.
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 William Pitcock
10 * Rights to this code are as documented in doc/pod/license.pod.
11 *
12 * $Id: mark.C,v 1.7 2007-09-16 18:54:43 pippijn Exp $
13 */
14
15 #include "atheme.h"
16 #include <util/numeric.h>
17 #include <libermyth.h>
18 #include <ermyth/module.h>
19 #include <account/mychan.h>
20
21 static char const rcsid[] = "$Id: mark.C,v 1.7 2007-09-16 18:54:43 pippijn Exp $";
22
23 REGISTER_MODULE ("chanserv/mark", false, "The Ermyth Team <http://ermyth.xinutec.org>");
24
25 static void cs_cmd_mark (sourceinfo_t *si, int parc, char *parv[]);
26
27 command_t const cs_mark = { "MARK", N_("Adds a note to a channel."), PRIV_MARK, 3, cs_cmd_mark };
28
29 E cmdvec cs_cmdtree;
30 E helpvec cs_helptree;
31
32 bool
33 _modinit (module *m)
34 {
35 cs_cmdtree << cs_mark;
36 help_addentry (cs_helptree, "MARK", "help/chanserv/mark", NULL);
37
38 return true;
39 }
40
41 void
42 _moddeinit ()
43 {
44 cs_cmdtree >> cs_mark;
45 help_delentry (cs_helptree, "MARK");
46 }
47
48 static void
49 cs_cmd_mark (sourceinfo_t *si, int parc, char *parv[])
50 {
51 char *target = parv[0];
52 char *action = parv[1];
53 char *info = parv[2];
54 mychan_t *mc;
55
56 if (!target || !action)
57 {
58 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "MARK");
59 command_fail (si, fault::needmoreparams, _("Usage: MARK <#channel> <ON|OFF> [note]"));
60 return;
61 }
62
63 if (target[0] != '#')
64 {
65 command_fail (si, fault::badparams, STR_INVALID_PARAMS, "MARK");
66 return;
67 }
68
69 if (!(mc = mychan_t::find (target)))
70 {
71 command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), target);
72 return;
73 }
74
75 if (!strcasecmp (action, "ON"))
76 {
77 if (!info)
78 {
79 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "MARK");
80 command_fail (si, fault::needmoreparams, _("Usage: MARK <#channel> ON <note>"));
81 return;
82 }
83
84 if (mc->find_metadata ("private:mark:setter"))
85 {
86 command_fail (si, fault::nochange, _("\2%s\2 is already marked."), target);
87 return;
88 }
89
90 mc->add_metadata ("private:mark:setter", get_oper_name (si));
91 mc->add_metadata ("private:mark:reason", info);
92 mc->add_metadata ("private:mark:timestamp", itoa (NOW));
93
94 wallops ("%s marked the channel \2%s\2.", get_oper_name (si), target);
95 logcommand (si, CMDLOG_ADMIN, "%s MARK ON", mc->name);
96 command_success_nodata (si, _("\2%s\2 is now marked."), target);
97 }
98 else if (!strcasecmp (action, "OFF"))
99 {
100 if (!mc->find_metadata ("private:mark:setter"))
101 {
102 command_fail (si, fault::nochange, _("\2%s\2 is not marked."), target);
103 return;
104 }
105
106 mc->del_metadata ("private:mark:setter");
107 mc->del_metadata ("private:mark:reason");
108 mc->del_metadata ("private:mark:timestamp");
109
110 wallops ("%s unmarked the channel \2%s\2.", get_oper_name (si), target);
111 logcommand (si, CMDLOG_ADMIN, "%s MARK OFF", mc->name);
112 command_success_nodata (si, _("\2%s\2 is now unmarked."), target);
113 }
114 else
115 {
116 command_fail (si, fault::badparams, STR_INVALID_PARAMS, "MARK");
117 command_fail (si, fault::badparams, _("Usage: MARK <#channel> <ON|OFF> [note]"));
118 }
119 }
120
121 /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
122 * vim:ts=8
123 * vim:sw=8
124 * vim:noexpandtab
125 */