cs_appendtopic.c

Go to the documentation of this file.
00001 /* cs_appendtopic.c - Add text to a channels topic
00002  *
00003  * (C) 2003-2007 Anope Team
00004  * Contact us at info@anope.org
00005  *
00006  * Based on the original module by SGR <Alex_SGR@ntlworld.com>
00007  * Included in the Anope module pack since Anope 1.7.9
00008  * Anope Coder: GeniusDex <geniusdex@anope.org>
00009  *
00010  * Please read COPYING and README for further details.
00011  *
00012  * Send bug reports to the Anope Coder instead of the module
00013  * author, because any changes since the inclusion into anope
00014  * are not supported by the original author.
00015  *
00016  */
00017 /*************************************************************************/
00018 
00019 #include "module.h"
00020 
00021 #define AUTHOR "SGR"
00022 #define VERSION "$Id: cs_appendtopic.c 1322 2007-12-28 19:12:02Z geniusdex $"
00023 
00024   /* ------------------------------------------------------------
00025    * Name: cs_appendtopic
00026    * Author: SGR <Alex_SGR@ntlworld.com>
00027    * Date: 31/08/2003
00028    * ------------------------------------------------------------
00029    * 
00030    * This module has no configurable options. For information on
00031    * this module, load it and refer to /ChanServ APPENDTOPIC HELP
00032    * 
00033    * Thanks to dengel, Rob and Certus for all there support. 
00034    * Especially Rob, who always manages to show me where I have 
00035    * not allocated any memory. Even if it takes a few weeks of
00036    * pestering to get him to look at it.
00037    * 
00038    * ------------------------------------------------------------
00039    */
00040 
00041 /* ---------------------------------------------------------------------- */
00042 /* DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING         */
00043 /* ---------------------------------------------------------------------- */
00044 
00045 #define LNG_NUM_STRINGS           3
00046 
00047 #define LNG_CHAN_HELP             0
00048 #define LNG_CHAN_HELP_APPENDTOPIC 1
00049 #define LNG_APPENDTOPIC_SYNTAX    2
00050 
00051 int my_cs_appendtopic(User * u);
00052 void my_cs_help(User * u);
00053 int my_cs_help_appendtopic(User * u);
00054 void my_add_languages(void);
00055 
00056 int AnopeInit(int argc, char **argv)
00057 {
00058     Command *c;
00059     int status;
00060 
00061     moduleAddAuthor(AUTHOR);
00062     moduleAddVersion(VERSION);
00063     moduleSetType(SUPPORTED);
00064 
00065     c = createCommand("APPENDTOPIC", my_cs_appendtopic, NULL, -1, -1, -1,
00066                       -1, -1);
00067     if ((status = moduleAddCommand(CHANSERV, c, MOD_HEAD))) {
00068         alog("[cs_appendtopic] Unable to create APPENDTOPIC command: %d",
00069              status);
00070         return MOD_STOP;
00071     }
00072     moduleAddHelp(c, my_cs_help_appendtopic);
00073     moduleSetChanHelp(my_cs_help);
00074 
00075     my_add_languages();
00076 
00077     alog("[cs_appendtopic] Loaded successfully");
00078 
00079     return MOD_CONT;
00080 }
00081 
00082 void AnopeFini(void)
00083 {
00084     alog("[cs_appendtopic] Unloaded successfully");
00085 }
00086 
00087 void my_cs_help(User * u)
00088 {
00089     moduleNoticeLang(s_ChanServ, u, LNG_CHAN_HELP);
00090 }
00091 
00092 int my_cs_help_appendtopic(User * u)
00093 {
00094     moduleNoticeLang(s_ChanServ, u, LNG_APPENDTOPIC_SYNTAX);
00095     notice(s_ChanServ, u->nick, " ");
00096     moduleNoticeLang(s_ChanServ, u, LNG_CHAN_HELP_APPENDTOPIC);
00097     return MOD_STOP;
00098 }
00099 
00100 int my_cs_appendtopic(User * u)
00101 {
00102     char *cur_buffer;
00103     char *chan;
00104     char *newtopic;
00105     char topic[1024];
00106     Channel *c;
00107     ChannelInfo *ci;
00108 
00109     cur_buffer = moduleGetLastBuffer();
00110     chan = myStrGetToken(cur_buffer, ' ', 0);
00111     newtopic = myStrGetTokenRemainder(cur_buffer, ' ', 1);
00112 
00113     if (!chan || !newtopic) {
00114         moduleNoticeLang(s_ChanServ, u, LNG_APPENDTOPIC_SYNTAX);
00115     } else if (!(c = findchan(chan))) {
00116         notice_lang(s_ChanServ, u, CHAN_X_NOT_IN_USE, chan);
00117     } else if (!(ci = c->ci)) {
00118         notice_lang(s_ChanServ, u, CHAN_X_NOT_REGISTERED, c->name);
00119     } else if (ci->flags & CI_VERBOTEN) {
00120         notice_lang(s_ChanServ, u, CHAN_X_FORBIDDEN, ci->name);
00121     } else if (!is_services_admin(u) && !check_access(u, ci, CA_TOPIC)) {
00122         notice_lang(s_ChanServ, u, PERMISSION_DENIED);
00123     } else {
00124         if (ci->last_topic) {
00125             snprintf(topic, sizeof(topic), "%s %s", ci->last_topic,
00126                      newtopic);
00127             free(ci->last_topic);
00128         } else {
00129             strscpy(topic, newtopic, sizeof(topic));
00130         }
00131 
00132         ci->last_topic = topic ? sstrdup(topic) : NULL;
00133         strscpy(ci->last_topic_setter, u->nick, NICKMAX);
00134         ci->last_topic_time = time(NULL);
00135 
00136         if (c->topic)
00137             free(c->topic);
00138         c->topic = topic ? sstrdup(topic) : NULL;
00139         strscpy(c->topic_setter, u->nick, NICKMAX);
00140         if (ircd->topictsbackward)
00141             c->topic_time = c->topic_time - 1;
00142         else
00143             c->topic_time = ci->last_topic_time;
00144 
00145         if (is_services_admin(u) && !check_access(u, ci, CA_TOPIC))
00146             alog("%s: %s!%s@%s changed topic of %s as services admin.",
00147                  s_ChanServ, u->nick, u->username, u->host, c->name);
00148         if (ircd->join2set) {
00149             if (whosends(ci) == s_ChanServ) {
00150                 anope_cmd_join(s_ChanServ, c->name, c->creation_time);
00151                 anope_cmd_mode(NULL, c->name, "+o %s", s_ChanServ);
00152             }
00153         }
00154         anope_cmd_topic(whosends(ci), c->name, u->nick, topic ? topic : "",
00155                         c->topic_time);
00156         if (ircd->join2set) {
00157             if (whosends(ci) == s_ChanServ) {
00158                 anope_cmd_part(s_ChanServ, c->name, NULL);
00159             }
00160         }
00161     }
00162     return MOD_CONT;
00163 }
00164 
00165 void my_add_languages(void)
00166 {
00167     /* English (US) */
00168     char *langtable_en_us[] = {
00169         /* LNG_CHAN_HELP */
00170         "    APPENDTOPIC   Add text to a channels topic",
00171         /* LNG_CHAN_HELP_APPENDTOPIC */
00172         "This command allows users to append text to a currently set\n"
00173             "channel topic. When TOPICLOCK is on, the topic is updated and\n"
00174             "the new, updated topic is locked.",
00175         /* LNG_APPENDTOPIC_SYNTAX */
00176         "Syntax: APPENDTOPIC channel text\n"
00177     };
00178 
00179     /* Dutch (NL) */
00180     char *langtable_nl[] = {
00181         /* LNG_CHAN_HELP */
00182         "    APPENDTOPIC   Voeg tekst aan een kanaal onderwerp toe",
00183         /* LNG_CHAN_HELP_APPENDTOPIC */
00184         "Dit command stelt gebruikers in staat om text toe te voegen\n"
00185             "achter het huidige onderwerp van een kanaal. Als TOPICLOCK aan\n"
00186             "staat, zal het onderwerp worden bijgewerkt en zal het nieuwe,\n"
00187             "bijgewerkte topic worden geforceerd.",
00188         /* LNG_APPENDTOPIC_SYNTAX */
00189         "Gebruik: APPENDTOPIC kanaal tekst\n"
00190     };
00191 
00192     /* German (DE) */
00193     char *langtable_de[] = {
00194         /* LNG_CHAN_HELP */
00195         "    APPENDTOPIC   Fügt einen Text zu einem Channel-Topic hinzu.",
00196         /* LNG_CHAN_HELP_APPENDTOPIC */
00197         "Dieser Befehl erlaubt Benutzern, einen Text zu dem vorhandenen Channel-Topic\n"
00198             "hinzuzufügen. Wenn TOPICLOCK gesetzt ist, wird das Topic aktualisiert\n"
00199             "und das neue, aktualisierte Topic wird gesperrt.",
00200         /* LNG_APPENDTOPIC_SYNTAX */
00201         "Syntax: APPENDTOPIC Channel Text\n"
00202     };
00203 
00204     /* Portuguese (PT) */
00205     char *langtable_pt[] = {
00206         /* LNG_CHAN_HELP */
00207         "    APPENDTOPIC   Adiciona texto ao tópico de um canal",
00208         /* LNG_CHAN_HELP_APPENDTOPIC */
00209         "Este comando permite aos usuários anexar texto a um tópico de canal\n"
00210             "já definido. Quando TOPICLOCK está ativado, o tópico é atualizado e\n"
00211             "o novo tópico é travado.",
00212         /* LNG_APPENDTOPIC_SYNTAX */
00213         "Sintaxe: APPENDTOPIC canal texto\n"
00214     };
00215 
00216     /* Italian (IT) */
00217     char *langtable_it[] = {
00218         /* LNG_CHAN_HELP */
00219         "    APPENDTOPIC   Aggiunge del testo al topic di un canale",
00220         /* LNG_CHAN_HELP_APPENDTOPIC */
00221         "Questo comando permette agli utenti di aggiungere del testo ad un topic di un canale\n"
00222             "giŕ impostato. Se TOPICLOCK č attivato, il topic viene aggiornato e il nuovo topic\n"
00223             "viene bloccato.",
00224         /* LNG_APPENDTOPIC_SYNTAX */
00225         "Sintassi: APPENDTOPIC canale testo\n"
00226     };
00227 
00228     moduleInsertLanguage(LANG_EN_US, LNG_NUM_STRINGS, langtable_en_us);
00229     moduleInsertLanguage(LANG_NL, LNG_NUM_STRINGS, langtable_nl);
00230     moduleInsertLanguage(LANG_DE, LNG_NUM_STRINGS, langtable_de);
00231     moduleInsertLanguage(LANG_PT, LNG_NUM_STRINGS, langtable_pt);
00232     moduleInsertLanguage(LANG_IT, LNG_NUM_STRINGS, langtable_it);
00233 }
00234 
00235 /* EOF */

Generated on Sun Dec 30 09:26:49 2007 for Anope by  doxygen 1.5.1-20070107