ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/chanserv/topic.C
Revision: 1.8
Committed: Sat Sep 22 14:27:27 2007 UTC (19 years, 1 month 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

# 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.8 * $Id: topic.C,v 1.7 2007-09-16 18:54:43 pippijn Exp $
13 pippijn 1.1 */
14    
15     #include "atheme.h"
16 pippijn 1.8 #include <libermyth.h>
17 pippijn 1.5 #include <ermyth/module.h>
18 pippijn 1.1 #include <account/mychan.h>
19     #include <account/myuser.h>
20     #include <account/chanacs.h>
21    
22 pippijn 1.8 static char const rcsid[] = "$Id: topic.C,v 1.7 2007-09-16 18:54:43 pippijn Exp $";
23 pippijn 1.1
24 pippijn 1.8 REGISTER_MODULE ("chanserv/topic", false, "The Ermyth Team <http://ermyth.xinutec.org>");
25 pippijn 1.1
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 pippijn 1.5 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 pippijn 1.1
34 pippijn 1.5 E cmdvec cs_cmdtree;
35     E helpvec cs_helptree;
36 pippijn 1.1
37 pippijn 1.5 bool
38     _modinit (module *m)
39 pippijn 1.1 {
40     cs_cmdtree << cs_topic;
41     cs_cmdtree << cs_topicappend;
42     cs_cmdtree << cs_topicprepend;
43    
44 pippijn 1.4 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 pippijn 1.5
48     return true;
49 pippijn 1.1 }
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 pippijn 1.5 char const *topicsetter;
71 pippijn 1.1 time_t prevtopicts;
72    
73     if (!chan || !topic)
74     {
75 pippijn 1.6 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "TOPIC");
76     command_fail (si, fault::needmoreparams, _("Syntax: TOPIC <#channel> <topic>"));
77 pippijn 1.1 return;
78     }
79    
80 pippijn 1.6 mc = mychan_t::find (chan);
81 pippijn 1.1 if (!mc)
82     {
83 pippijn 1.6 command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), chan);
84 pippijn 1.1 return;
85     }
86    
87     c = channel_find (chan);
88     if (!c)
89     {
90 pippijn 1.6 command_fail (si, fault::nosuch_target, _("\2%s\2 is currently empty."), chan);
91 pippijn 1.1 return;
92     }
93    
94     if (mc->find_metadata ("private:close:closer"))
95     {
96 pippijn 1.6 command_fail (si, fault::noprivs, _("\2%s\2 is closed."), chan);
97 pippijn 1.1 return;
98     }
99    
100     if (!chanacs_source_has_flag (mc, si, CA_TOPIC))
101     {
102 pippijn 1.6 command_fail (si, fault::noprivs, _("You are not authorized to perform this operation."));
103 pippijn 1.1 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 pippijn 1.5 phandler->topic_sts (c, topicsetter, NOW, prevtopicts, topic);
115 pippijn 1.1
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 pippijn 1.5 char const *topicsetter;
130 pippijn 1.1 time_t prevtopicts;
131    
132     if (!chan || !topic)
133     {
134 pippijn 1.6 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "TOPICAPPEND");
135     command_fail (si, fault::needmoreparams, _("Syntax: TOPICAPPEND <#channel> <topic>"));
136 pippijn 1.1 return;
137     }
138    
139 pippijn 1.6 mc = mychan_t::find (chan);
140 pippijn 1.1 if (!mc)
141     {
142 pippijn 1.6 command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), chan);
143 pippijn 1.1 return;
144     }
145    
146     c = channel_find (chan);
147     if (!c)
148     {
149 pippijn 1.6 command_fail (si, fault::nosuch_target, _("\2%s\2 is currently empty."), chan);
150 pippijn 1.1 return;
151     }
152    
153     if (!chanacs_source_has_flag (mc, si, CA_TOPIC))
154     {
155 pippijn 1.6 command_fail (si, fault::noprivs, _("You are not authorized to perform this operation."));
156 pippijn 1.1 return;
157     }
158    
159     if (mc->find_metadata ("private:close:closer"))
160     {
161 pippijn 1.6 command_fail (si, fault::noprivs, _("\2%s\2 is closed."), chan);
162 pippijn 1.1 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 pippijn 1.5 phandler->topic_sts (c, topicsetter, NOW, prevtopicts, topicbuf);
185 pippijn 1.1
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 pippijn 1.5 char const *topicsetter;
200 pippijn 1.1 time_t prevtopicts;
201    
202     if (!chan || !topic)
203     {
204 pippijn 1.6 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "TOPICPREPEND");
205     command_fail (si, fault::needmoreparams, _("Syntax: TOPICPREPEND <#channel> <topic>"));
206 pippijn 1.1 return;
207     }
208    
209 pippijn 1.6 mc = mychan_t::find (chan);
210 pippijn 1.1 if (!mc)
211     {
212 pippijn 1.6 command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), chan);
213 pippijn 1.1 return;
214     }
215    
216     c = channel_find (chan);
217     if (!c)
218     {
219 pippijn 1.6 command_fail (si, fault::nosuch_target, _("\2%s\2 is currently empty."), chan);
220 pippijn 1.1 return;
221     }
222    
223     if (!chanacs_source_has_flag (mc, si, CA_TOPIC))
224     {
225 pippijn 1.6 command_fail (si, fault::noprivs, _("You are not authorized to perform this operation."));
226 pippijn 1.1 return;
227     }
228    
229     if (mc->find_metadata ("private:close:closer"))
230     {
231 pippijn 1.6 command_fail (si, fault::noprivs, _("\2%s\2 is closed."), chan);
232 pippijn 1.1 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 pippijn 1.5 phandler->topic_sts (c, topicsetter, NOW, prevtopicts, topicbuf);
255 pippijn 1.1
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     }