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

File Contents

# Content
1 /**
2 * topic.C: This file contains code for the ChanServ TOPIC functions.
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, et al.
10 * Rights to this code are as documented in doc/pod/license.pod.
11 *
12 * $Id: topic.C,v 1.7 2007-09-16 18:54:43 pippijn Exp $
13 */
14
15 #include "atheme.h"
16 #include <libermyth.h>
17 #include <ermyth/module.h>
18 #include <account/mychan.h>
19 #include <account/myuser.h>
20 #include <account/chanacs.h>
21
22 static char const rcsid[] = "$Id: topic.C,v 1.7 2007-09-16 18:54:43 pippijn Exp $";
23
24 REGISTER_MODULE ("chanserv/topic", false, "The Ermyth Team <http://ermyth.xinutec.org>");
25
26 static void cs_cmd_topic (sourceinfo_t *si, int parc, char *parv[]);
27 static void cs_cmd_topicappend (sourceinfo_t *si, int parc, char *parv[]);
28 static void cs_cmd_topicprepend (sourceinfo_t *si, int parc, char *parv[]);
29
30 command_t const cs_topic = { "TOPIC", N_("Sets a topic on a channel."), AC_NONE, 2, cs_cmd_topic };
31 command_t const cs_topicappend = { "TOPICAPPEND", N_("Appends a topic on a channel."), AC_NONE, 2, cs_cmd_topicappend };
32 command_t const cs_topicprepend = { "TOPICPREPEND", N_("Prepends a topic on a channel."), AC_NONE, 2, cs_cmd_topicprepend };
33
34 E cmdvec cs_cmdtree;
35 E helpvec cs_helptree;
36
37 bool
38 _modinit (module *m)
39 {
40 cs_cmdtree << cs_topic;
41 cs_cmdtree << cs_topicappend;
42 cs_cmdtree << cs_topicprepend;
43
44 help_addentry (cs_helptree, "TOPIC", "help/chanserv/topic", NULL);
45 help_addentry (cs_helptree, "TOPICAPPEND", "help/chanserv/topicappend", NULL);
46 help_addentry (cs_helptree, "TOPICPREPEND", "help/chanserv/topicprepend", NULL);
47
48 return true;
49 }
50
51 void
52 _moddeinit ()
53 {
54 cs_cmdtree >> cs_topic;
55 cs_cmdtree >> cs_topicappend;
56 cs_cmdtree >> cs_topicprepend;
57
58 help_delentry (cs_helptree, "TOPIC");
59 help_delentry (cs_helptree, "TOPICAPPEND");
60 help_delentry (cs_helptree, "TOPICPREPEND");
61 }
62
63 static void
64 cs_cmd_topic (sourceinfo_t *si, int parc, char *parv[])
65 {
66 char *chan = parv[0];
67 char *topic = parv[1];
68 mychan_t *mc;
69 channel_t *c;
70 char const *topicsetter;
71 time_t prevtopicts;
72
73 if (!chan || !topic)
74 {
75 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "TOPIC");
76 command_fail (si, fault::needmoreparams, _("Syntax: TOPIC <#channel> <topic>"));
77 return;
78 }
79
80 mc = mychan_t::find (chan);
81 if (!mc)
82 {
83 command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), chan);
84 return;
85 }
86
87 c = channel_find (chan);
88 if (!c)
89 {
90 command_fail (si, fault::nosuch_target, _("\2%s\2 is currently empty."), chan);
91 return;
92 }
93
94 if (mc->find_metadata ("private:close:closer"))
95 {
96 command_fail (si, fault::noprivs, _("\2%s\2 is closed."), chan);
97 return;
98 }
99
100 if (!chanacs_source_has_flag (mc, si, CA_TOPIC))
101 {
102 command_fail (si, fault::noprivs, _("You are not authorized to perform this operation."));
103 return;
104 }
105
106 if (si->su != NULL)
107 topicsetter = si->su->nick;
108 else if (si->smu != NULL)
109 topicsetter = si->smu->name;
110 else
111 topicsetter = "unknown";
112 prevtopicts = c->topicts;
113 handle_topic (c, topicsetter, NOW, topic);
114 phandler->topic_sts (c, topicsetter, NOW, prevtopicts, topic);
115
116 logcommand (si, CMDLOG_SET, "%s TOPIC", mc->name);
117 if (!chanuser_find (c, si->su))
118 command_success_nodata (si, _("Topic set to \2%s\2 on \2%s\2."), topic, chan);
119 }
120
121 static void
122 cs_cmd_topicappend (sourceinfo_t *si, int parc, char *parv[])
123 {
124 char *chan = parv[0];
125 char *topic = parv[1];
126 mychan_t *mc;
127 char topicbuf[BUFSIZE];
128 channel_t *c;
129 char const *topicsetter;
130 time_t prevtopicts;
131
132 if (!chan || !topic)
133 {
134 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "TOPICAPPEND");
135 command_fail (si, fault::needmoreparams, _("Syntax: TOPICAPPEND <#channel> <topic>"));
136 return;
137 }
138
139 mc = mychan_t::find (chan);
140 if (!mc)
141 {
142 command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), chan);
143 return;
144 }
145
146 c = channel_find (chan);
147 if (!c)
148 {
149 command_fail (si, fault::nosuch_target, _("\2%s\2 is currently empty."), chan);
150 return;
151 }
152
153 if (!chanacs_source_has_flag (mc, si, CA_TOPIC))
154 {
155 command_fail (si, fault::noprivs, _("You are not authorized to perform this operation."));
156 return;
157 }
158
159 if (mc->find_metadata ("private:close:closer"))
160 {
161 command_fail (si, fault::noprivs, _("\2%s\2 is closed."), chan);
162 return;
163 }
164
165 topicbuf[0] = '\0';
166
167 if (c->topic)
168 {
169 strlcpy (topicbuf, c->topic, BUFSIZE);
170 strlcat (topicbuf, " | ", BUFSIZE);
171 strlcat (topicbuf, topic, BUFSIZE);
172 }
173 else
174 strlcpy (topicbuf, topic, BUFSIZE);
175
176 if (si->su != NULL)
177 topicsetter = si->su->nick;
178 else if (si->smu != NULL)
179 topicsetter = si->smu->name;
180 else
181 topicsetter = "unknown";
182 prevtopicts = c->topicts;
183 handle_topic (c, topicsetter, NOW, topicbuf);
184 phandler->topic_sts (c, topicsetter, NOW, prevtopicts, topicbuf);
185
186 logcommand (si, CMDLOG_SET, "%s TOPICAPPEND", mc->name);
187 if (!chanuser_find (c, si->su))
188 command_success_nodata (si, _("Topic set to \2%s\2 on \2%s\2."), c->topic, chan);
189 }
190
191 static void
192 cs_cmd_topicprepend (sourceinfo_t *si, int parc, char *parv[])
193 {
194 char *chan = parv[0];
195 char *topic = parv[1];
196 mychan_t *mc;
197 char topicbuf[BUFSIZE];
198 channel_t *c;
199 char const *topicsetter;
200 time_t prevtopicts;
201
202 if (!chan || !topic)
203 {
204 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "TOPICPREPEND");
205 command_fail (si, fault::needmoreparams, _("Syntax: TOPICPREPEND <#channel> <topic>"));
206 return;
207 }
208
209 mc = mychan_t::find (chan);
210 if (!mc)
211 {
212 command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), chan);
213 return;
214 }
215
216 c = channel_find (chan);
217 if (!c)
218 {
219 command_fail (si, fault::nosuch_target, _("\2%s\2 is currently empty."), chan);
220 return;
221 }
222
223 if (!chanacs_source_has_flag (mc, si, CA_TOPIC))
224 {
225 command_fail (si, fault::noprivs, _("You are not authorized to perform this operation."));
226 return;
227 }
228
229 if (mc->find_metadata ("private:close:closer"))
230 {
231 command_fail (si, fault::noprivs, _("\2%s\2 is closed."), chan);
232 return;
233 }
234
235 topicbuf[0] = '\0';
236
237 if (c->topic)
238 {
239 strlcpy (topicbuf, topic, BUFSIZE);
240 strlcat (topicbuf, " | ", BUFSIZE);
241 strlcat (topicbuf, c->topic, BUFSIZE);
242 }
243 else
244 strlcpy (topicbuf, topic, BUFSIZE);
245
246 if (si->su != NULL)
247 topicsetter = si->su->nick;
248 else if (si->smu != NULL)
249 topicsetter = si->smu->name;
250 else
251 topicsetter = "unknown";
252 prevtopicts = c->topicts;
253 handle_topic (c, topicsetter, NOW, topicbuf);
254 phandler->topic_sts (c, topicsetter, NOW, prevtopicts, topicbuf);
255
256 logcommand (si, CMDLOG_SET, "%s TOPICPREPEND", mc->name);
257 if (!chanuser_find (c, si->su))
258 command_success_nodata (si, _("Topic set to \2%s\2 on \2%s\2."), c->topic, chan);
259 }