ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/chanserv/topic.C
Revision: 1.7
Committed: Sun Sep 16 18:54:43 2007 UTC (19 years, 2 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.6: +10 -5 lines
Log Message:
#defines to enum

File Contents

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