Anope IRC Services  Version 1.8
cs_appendtopic.c
Go to the documentation of this file.
1 /* cs_appendtopic.c - Add text to a channels topic
2  *
3  * (C) 2003-2014 Anope Team
4  * Contact us at team@anope.org
5  *
6  * Based on the original module by SGR <Alex_SGR@ntlworld.com>
7  * Included in the Anope module pack since Anope 1.7.9
8  * Anope Coder: GeniusDex <geniusdex@anope.org>
9  *
10  * Please read COPYING and README for further details.
11  *
12  * Send bug reports to the Anope Coder instead of the module
13  * author, because any changes since the inclusion into anope
14  * are not supported by the original author.
15  *
16  */
17 /*************************************************************************/
18 
19 #include "module.h"
20 
21 #define AUTHOR "SGR"
22 #define VERSION VERSION_STRING
23 
24  /* ------------------------------------------------------------
25  * Name: cs_appendtopic
26  * Author: SGR <Alex_SGR@ntlworld.com>
27  * Date: 31/08/2003
28  * ------------------------------------------------------------
29  *
30  * This module has no configurable options. For information on
31  * this module, load it and refer to /ChanServ APPENDTOPIC HELP
32  *
33  * Thanks to dengel, Rob and Certus for all there support.
34  * Especially Rob, who always manages to show me where I have
35  * not allocated any memory. Even if it takes a few weeks of
36  * pestering to get him to look at it.
37  *
38  * ------------------------------------------------------------
39  */
40 
41 /* ---------------------------------------------------------------------- */
42 /* DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING */
43 /* ---------------------------------------------------------------------- */
44 
45 #define LNG_NUM_STRINGS 3
46 
47 #define LNG_CHAN_HELP 0
48 #define LNG_CHAN_HELP_APPENDTOPIC 1
49 #define LNG_APPENDTOPIC_SYNTAX 2
50 
51 static int my_cs_appendtopic(User * u);
52 static void my_cs_help(User * u);
53 static int my_cs_help_appendtopic(User * u);
54 static void my_add_languages(void);
55 
56 int AnopeInit(int argc, char **argv)
57 {
58  Command *c;
59  int status;
60 
64 
65  c = createCommand("APPENDTOPIC", my_cs_appendtopic, NULL, -1, -1, -1,
66  -1, -1);
67  if ((status = moduleAddCommand(CHANSERV, c, MOD_HEAD))) {
68  alog("[cs_appendtopic] Unable to create APPENDTOPIC command: %d",
69  status);
70  return MOD_STOP;
71  }
74 
76 
77  alog("[cs_appendtopic] Loaded successfully");
78 
79  return MOD_CONT;
80 }
81 
82 void AnopeFini(void)
83 {
84  alog("[cs_appendtopic] Unloaded successfully");
85 }
86 
87 static void my_cs_help(User * u)
88 {
90 }
91 
93 {
95  notice(s_ChanServ, u->nick, " ");
97  return MOD_STOP;
98 }
99 
100 static int my_cs_appendtopic(User * u)
101 {
102  char *cur_buffer;
103  char *chan;
104  char *newtopic;
105  char topic[1024];
106  Channel *c;
107  ChannelInfo *ci;
108 
109  cur_buffer = moduleGetLastBuffer();
110  chan = myStrGetToken(cur_buffer, ' ', 0);
111  newtopic = myStrGetTokenRemainder(cur_buffer, ' ', 1);
112 
113  if (!chan || !newtopic) {
115  } else if (!(c = findchan(chan))) {
116  notice_lang(s_ChanServ, u, CHAN_X_NOT_IN_USE, chan);
117  } else if (!(ci = c->ci)) {
118  notice_lang(s_ChanServ, u, CHAN_X_NOT_REGISTERED, c->name);
119  } else if (ci->flags & CI_VERBOTEN) {
120  notice_lang(s_ChanServ, u, CHAN_X_FORBIDDEN, ci->name);
121  } else if (!is_services_admin(u) && !check_access(u, ci, CA_TOPIC)) {
122  notice_lang(s_ChanServ, u, PERMISSION_DENIED);
123  } else {
124  if (ci->last_topic) {
125  snprintf(topic, sizeof(topic), "%s %s", ci->last_topic,
126  newtopic);
127  free(ci->last_topic);
128  } else {
129  strscpy(topic, newtopic, sizeof(topic));
130  }
131 
132  ci->last_topic = *topic ? sstrdup(topic) : NULL;
134  ci->last_topic_time = time(NULL);
135 
136  if (c->topic)
137  free(c->topic);
138  c->topic = *topic ? sstrdup(topic) : NULL;
139  strscpy(c->topic_setter, u->nick, NICKMAX);
140  if (ircd->topictsbackward)
141  c->topic_time = c->topic_time - 1;
142  else
143  c->topic_time = ci->last_topic_time;
144 
145  if (is_services_admin(u) && !check_access(u, ci, CA_TOPIC))
146  alog("%s: %s!%s@%s changed topic of %s as services admin.",
147  s_ChanServ, u->nick, u->username, u->host, c->name);
148  if (ircd->join2set) {
149  if (whosends(ci) == s_ChanServ) {
151  anope_cmd_mode(NULL, c->name, "+o %s", GET_BOT(s_ChanServ));
152  }
153  }
154  anope_cmd_topic(whosends(ci), c->name, u->nick, topic, c->topic_time);
155  if (ircd->join2set) {
156  if (whosends(ci) == s_ChanServ) {
157  anope_cmd_part(s_ChanServ, c->name, NULL);
158  }
159  }
160  }
161  Anope_Free(chan);
162  Anope_Free(newtopic);
163  return MOD_CONT;
164 }
165 
166 static void my_add_languages(void)
167 {
168  /* English (US) */
169  char *langtable_en_us[] = {
170  /* LNG_CHAN_HELP */
171  " APPENDTOPIC Add text to a channels topic",
172  /* LNG_CHAN_HELP_APPENDTOPIC */
173  "This command allows users to append text to a currently set\n"
174  "channel topic. When TOPICLOCK is on, the topic is updated and\n"
175  "the new, updated topic is locked.",
176  /* LNG_APPENDTOPIC_SYNTAX */
177  "Syntax: APPENDTOPIC channel text\n"
178  };
179 
180  /* Dutch (NL) */
181  char *langtable_nl[] = {
182  /* LNG_CHAN_HELP */
183  " APPENDTOPIC Voeg tekst aan een kanaal onderwerp toe",
184  /* LNG_CHAN_HELP_APPENDTOPIC */
185  "Dit command stelt gebruikers in staat om text toe te voegen\n"
186  "achter het huidige onderwerp van een kanaal. Als TOPICLOCK aan\n"
187  "staat, zal het onderwerp worden bijgewerkt en zal het nieuwe,\n"
188  "bijgewerkte topic worden geforceerd.",
189  /* LNG_APPENDTOPIC_SYNTAX */
190  "Gebruik: APPENDTOPIC kanaal tekst\n"
191  };
192 
193  /* German (DE) */
194  char *langtable_de[] = {
195  /* LNG_CHAN_HELP */
196  " APPENDTOPIC Fgt einen Text zu einem Channel-Topic hinzu.",
197  /* LNG_CHAN_HELP_APPENDTOPIC */
198  "Dieser Befehl erlaubt Benutzern, einen Text zu dem vorhandenen Channel-Topic\n"
199  "hinzuzufgen. Wenn TOPICLOCK gesetzt ist, wird das Topic aktualisiert\n"
200  "und das neue, aktualisierte Topic wird gesperrt.",
201  /* LNG_APPENDTOPIC_SYNTAX */
202  "Syntax: APPENDTOPIC Channel Text\n"
203  };
204 
205  /* Portuguese (PT) */
206  char *langtable_pt[] = {
207  /* LNG_CHAN_HELP */
208  " APPENDTOPIC Adiciona texto ao tpico de um canal",
209  /* LNG_CHAN_HELP_APPENDTOPIC */
210  "Este comando permite aos usurios anexar texto a um tpico de canal\n"
211  "j definido. Quando TOPICLOCK est ativado, o tpico atualizado e\n"
212  "o novo tpico travado.",
213  /* LNG_APPENDTOPIC_SYNTAX */
214  "Sintaxe: APPENDTOPIC canal texto\n"
215  };
216 
217  /* Russian (RU) */
218  char *langtable_ru[] = {
219  /* LNG_CHAN_HELP */
220  " APPENDTOPIC ",
221  /* LNG_CHAN_HELP_APPENDTOPIC */
222  " , n" ". TOPICLOCK, .\n" ": , .\n", /* LNG_APPENDTOPIC_SYNTAX */ ": APPENDTOPIC # \n" }; /* Italian (IT) */ char *langtable_it[] = { /* LNG_CHAN_HELP */ " APPENDTOPIC Aggiunge del testo al topic di un canale", /* LNG_CHAN_HELP_APPENDTOPIC */ "Questo comando permette agli utenti di aggiungere del testo ad un topic di un canale\n" "gi impostato. Se TOPICLOCK attivato, il topic viene aggiornato e il nuovo topic\n" "viene bloccato.", /* LNG_APPENDTOPIC_SYNTAX */ "Sintassi: APPENDTOPIC canale testo\n" }; /* French (US) */ char *langtable_fr[] = { /* LNG_CHAN_HELP */ " APPENDTOPIC Ajoute du texte dans le sujet d'un salon", /* LNG_CHAN_HELP_APPENDTOPIC */ "Cette commande permet aux utilisateurs d'ajouter du texte un sujet\n" "du salon. Quand TOPICLOCK est actif, le sujet est mis jour et\n" "le nouveau sujet modifi est vrrouill.", /* LNG_APPENDTOPIC_SYNTAX */ "Syntaxe: \002APPENDTOPIC \037canal\037 \037texte\037\002\n" }; moduleInsertLanguage(LANG_EN_US, LNG_NUM_STRINGS, langtable_en_us); moduleInsertLanguage(LANG_NL, LNG_NUM_STRINGS, langtable_nl); moduleInsertLanguage(LANG_DE, LNG_NUM_STRINGS, langtable_de); moduleInsertLanguage(LANG_PT, LNG_NUM_STRINGS, langtable_pt); moduleInsertLanguage(LANG_RU, LNG_NUM_STRINGS, langtable_ru); moduleInsertLanguage(LANG_IT, LNG_NUM_STRINGS, langtable_it); moduleInsertLanguage(LANG_FR, LNG_NUM_STRINGS, langtable_fr); } /* EOF */ \n"
223  ". TOPICLOCK, .\n"
224  ": , .\n",
225  /* LNG_APPENDTOPIC_SYNTAX */
226  ": APPENDTOPIC # \n"
227  };
228 
229  /* Italian (IT) */
230  char *langtable_it[] = {
231  /* LNG_CHAN_HELP */
232  " APPENDTOPIC Aggiunge del testo al topic di un canale",
233  /* LNG_CHAN_HELP_APPENDTOPIC */
234  "Questo comando permette agli utenti di aggiungere del testo ad un topic di un canale\n"
235  "gi impostato. Se TOPICLOCK attivato, il topic viene aggiornato e il nuovo topic\n"
236  "viene bloccato.",
237  /* LNG_APPENDTOPIC_SYNTAX */
238  "Sintassi: APPENDTOPIC canale testo\n"
239  };
240 
241  /* French (US) */
242  char *langtable_fr[] = {
243  /* LNG_CHAN_HELP */
244  " APPENDTOPIC Ajoute du texte dans le sujet d'un salon",
245  /* LNG_CHAN_HELP_APPENDTOPIC */
246  "Cette commande permet aux utilisateurs d'ajouter du texte un sujet\n"
247  "du salon. Quand TOPICLOCK est actif, le sujet est mis jour et\n"
248  "le nouveau sujet modifi est vrrouill.",
249  /* LNG_APPENDTOPIC_SYNTAX */
250  "Syntaxe: \002APPENDTOPIC \037canal\037 \037texte\037\002\n"
251  };
252 
260 }
261 
262 /* EOF */
#define LNG_NUM_STRINGS
#define LANG_DE
Definition: services.h:1324
#define Anope_Free(x)
Definition: extern.h:1391
#define LNG_CHAN_HELP
char nick[NICKMAX]
Definition: services.h:875
E int snprintf(char *buf, size_t size, const char *fmt,...)
Definition: compat.c:37
E void anope_cmd_part(char *nick, char *chan, const char *fmt,...)
Definition: ircd.c:367
MDE void moduleNoticeLang(char *source, User *u, int number,...)
Definition: modules.c:2680
E IRCDVar * ircd
Definition: extern.h:39
#define VERSION
#define LANG_RU
Definition: services.h:1328
E int check_access(User *user, ChannelInfo *ci, int what)
Definition: chanserv.c:1974
E char * myStrGetTokenRemainder(const char *str, const char dilim, int token_number)
Definition: misc.c:720
#define LANG_NL
Definition: services.h:1327
E void notice(char *source, char *dest, const char *fmt,...)
Definition: send.c:274
E void anope_cmd_join(char *user, char *channel, time_t chantime)
Definition: ircd.c:352
#define AUTHOR
#define CI_VERBOTEN
Definition: services.h:725
char topic_setter[NICKMAX]
Definition: services.h:1004
char * host
Definition: services.h:878
E char * strscpy(char *d, const char *s, size_t len)
Definition: db-merger.c:1886
MDE void moduleAddAuthor(const char *author)
Definition: modules.c:1772
ChannelInfo * ci
Definition: services.h:1001
char name[CHANMAX]
Definition: services.h:654
E void notice_lang(char *source, User *dest, int message,...)
Definition: send.c:169
MDE void moduleSetType(MODType type)
Definition: modules.c:818
MDE char * moduleGetLastBuffer(void)
Definition: modules.c:1988
time_t last_topic_time
Definition: services.h:667
char last_topic_setter[NICKMAX]
Definition: services.h:666
char * last_topic
Definition: services.h:665
E Channel * findchan(const char *chan)
Definition: channels.c:394
E char * sstrdup(const char *s)
Definition: memory.c:105
E void anope_cmd_topic(char *whosets, char *chan, char *whosetit, char *topic, time_t when)
Definition: ircd.c:145
#define MOD_STOP
Definition: modules.h:53
#define LANG_FR
Definition: services.h:1321
uint32 flags
Definition: services.h:669
#define LNG_CHAN_HELP_APPENDTOPIC
static void my_add_languages(void)
static int my_cs_help_appendtopic(User *u)
time_t creation_time
Definition: services.h:1002
MDE void moduleAddVersion(const char *version)
Definition: modules.c:1760
#define LNG_APPENDTOPIC_SYNTAX
MDE void moduleSetChanHelp(void(*func)(User *u))
Definition: modules.c:2090
Command * c
Definition: ns_recover.c:17
#define CHANSERV
Definition: modules.h:60
E void alog(const char *fmt,...) FORMAT(printf
#define MOD_CONT
Definition: modules.h:54
#define LANG_IT
Definition: services.h:1323
E int is_services_admin(User *u)
Definition: operserv.c:591
MDE void moduleInsertLanguage(int langNumber, int ac, char **av)
Definition: modules.c:2650
int topictsbackward
Definition: services.h:322
#define whosends(ci)
Definition: extern.h:163
char * username
Definition: services.h:877
char * topic
Definition: services.h:1003
E void anope_cmd_mode(char *source, char *dest, const char *fmt,...)
Definition: ircd.c:211
MDE Command * createCommand(const char *name, int(*func)(User *u), int(*has_priv)(User *u), int help_all, int help_reg, int help_oper, int help_admin, int help_root)
Definition: modules.c:987
#define NICKMAX
Definition: config.h:62
time_t topic_time
Definition: services.h:1005
E char * myStrGetToken(const char *str, const char dilim, int token_number)
Definition: misc.c:654
int join2set
Definition: services.h:318
#define LANG_EN_US
Definition: services.h:1315
MDE int moduleAddHelp(Command *c, int(*func)(User *u))
Definition: modules.c:2064
char name[CHANMAX]
Definition: services.h:1000
static int my_cs_appendtopic(User *u)
E char * s_ChanServ
Definition: extern.h:285
#define GET_BOT(bot)
Definition: services.h:271
MDE int moduleAddCommand(CommandHash *cmdTable[], Command *c, int pos)
Definition: modules.c:1082
#define MOD_HEAD
Definition: module.h:12
static void my_cs_help(User *u)
int AnopeInit(int argc, char **argv)
void AnopeFini(void)
#define LANG_PT
Definition: services.h:1320
#define CA_TOPIC
Definition: services.h:787