cs_appendtopic.c

Go to the documentation of this file.
00001 /* cs_appendtopic.c - Add text to a channels topic
00002  *
00003  * (C) 2003-2013 Anope Team
00004  * Contact us at team@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 VERSION_STRING
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 static int my_cs_appendtopic(User * u);
00052 static void my_cs_help(User * u);
00053 static int my_cs_help_appendtopic(User * u);
00054 static 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 static void my_cs_help(User * u)
00088 {
00089     moduleNoticeLang(s_ChanServ, u, LNG_CHAN_HELP);
00090 }
00091 
00092 static 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 static 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", GET_BOT(s_ChanServ));
00152             }
00153         }
00154         anope_cmd_topic(whosends(ci), c->name, u->nick, topic, c->topic_time);
00155         if (ircd->join2set) {
00156             if (whosends(ci) == s_ChanServ) {
00157                 anope_cmd_part(s_ChanServ, c->name, NULL);
00158             }
00159         }
00160     }
00161     return MOD_CONT;
00162 }
00163 
00164 static void my_add_languages(void)
00165 {
00166     /* English (US) */
00167     char *langtable_en_us[] = {
00168         /* LNG_CHAN_HELP */
00169         "    APPENDTOPIC   Add text to a channels topic",
00170         /* LNG_CHAN_HELP_APPENDTOPIC */
00171         "This command allows users to append text to a currently set\n"
00172             "channel topic. When TOPICLOCK is on, the topic is updated and\n"
00173             "the new, updated topic is locked.",
00174         /* LNG_APPENDTOPIC_SYNTAX */
00175         "Syntax: APPENDTOPIC channel text\n"
00176     };
00177 
00178     /* Dutch (NL) */
00179     char *langtable_nl[] = {
00180         /* LNG_CHAN_HELP */
00181         "    APPENDTOPIC   Voeg tekst aan een kanaal onderwerp toe",
00182         /* LNG_CHAN_HELP_APPENDTOPIC */
00183         "Dit command stelt gebruikers in staat om text toe te voegen\n"
00184             "achter het huidige onderwerp van een kanaal. Als TOPICLOCK aan\n"
00185             "staat, zal het onderwerp worden bijgewerkt en zal het nieuwe,\n"
00186             "bijgewerkte topic worden geforceerd.",
00187         /* LNG_APPENDTOPIC_SYNTAX */
00188         "Gebruik: APPENDTOPIC kanaal tekst\n"
00189     };
00190 
00191         /* German (DE) */
00192     char *langtable_de[] = {
00193         /* LNG_CHAN_HELP */
00194         "    APPENDTOPIC   Fьgt einen Text zu einem Channel-Topic hinzu.",
00195         /* LNG_CHAN_HELP_APPENDTOPIC */
00196         "Dieser Befehl erlaubt Benutzern, einen Text zu dem vorhandenen Channel-Topic\n"
00197             "hinzuzufьgen. Wenn TOPICLOCK gesetzt ist, wird das Topic aktualisiert\n"
00198             "und das neue, aktualisierte Topic wird gesperrt.",
00199         /* LNG_APPENDTOPIC_SYNTAX */
00200         "Syntax: APPENDTOPIC Channel Text\n"
00201     };
00202 
00203     /* Portuguese (PT) */
00204     char *langtable_pt[] = {
00205         /* LNG_CHAN_HELP */
00206         "    APPENDTOPIC   Adiciona texto ao tуpico de um canal",
00207         /* LNG_CHAN_HELP_APPENDTOPIC */
00208         "Este comando permite aos usuбrios anexar texto a um tуpico de canal\n"
00209             "jб definido. Quando TOPICLOCK estб ativado, o tуpico й atualizado e\n"
00210             "o novo tуpico й travado.",
00211         /* LNG_APPENDTOPIC_SYNTAX */
00212         "Sintaxe: APPENDTOPIC canal texto\n"
00213     };
00214 
00215     /* Russian (RU) */
00216     char *langtable_ru[] = {
00217         /* LNG_CHAN_HELP */
00218         "    APPENDTOPIC   Добавляет текст к топику канала",
00219         /* LNG_CHAN_HELP_APPENDTOPIC */
00220         "Данная команда позволяет добавить текст к топику, который установлен на указанном\n"
00221             "канале. Если активирован режим TOPICLOCK, топик будет обновлен и заблокирован.\n"
00222             "Примечание: текст будет ДОБАВЛЕН к топику, то есть старый топик удален НЕ БУДЕТ.\n",
00223         /* LNG_APPENDTOPIC_SYNTAX */
00224         "Синтаксис: APPENDTOPIC #канал текст\n"
00225     };
00226 
00227     /* Italian (IT) */
00228     char *langtable_it[] = {
00229         /* LNG_CHAN_HELP */
00230         "    APPENDTOPIC   Aggiunge del testo al topic di un canale",
00231         /* LNG_CHAN_HELP_APPENDTOPIC */
00232         "Questo comando permette agli utenti di aggiungere del testo ad un topic di un canale\n"
00233             "giа impostato. Se TOPICLOCK и attivato, il topic viene aggiornato e il nuovo topic\n"
00234             "viene bloccato.",
00235         /* LNG_APPENDTOPIC_SYNTAX */
00236         "Sintassi: APPENDTOPIC canale testo\n"
00237     };
00238 
00239     /* French (US) */
00240     char *langtable_fr[] = {
00241         /* LNG_CHAN_HELP */
00242         "    APPENDTOPIC   Ajoute du texte dans le sujet d'un salon",
00243         /* LNG_CHAN_HELP_APPENDTOPIC */
00244         "Cette commande permet aux utilisateurs d'ajouter du texte а un sujet\n"
00245             "du salon. Quand TOPICLOCK est actif, le sujet est mis а jour et\n"
00246             "le nouveau sujet modifiй est vйrrouillй.",
00247         /* LNG_APPENDTOPIC_SYNTAX */
00248         "Syntaxe: \002APPENDTOPIC \037canal\037 \037texte\037\002\n"
00249     };
00250 
00251     moduleInsertLanguage(LANG_EN_US, LNG_NUM_STRINGS, langtable_en_us);
00252     moduleInsertLanguage(LANG_NL, LNG_NUM_STRINGS, langtable_nl);
00253     moduleInsertLanguage(LANG_DE, LNG_NUM_STRINGS, langtable_de);
00254     moduleInsertLanguage(LANG_PT, LNG_NUM_STRINGS, langtable_pt);
00255     moduleInsertLanguage(LANG_RU, LNG_NUM_STRINGS, langtable_ru);
00256         moduleInsertLanguage(LANG_IT, LNG_NUM_STRINGS, langtable_it);
00257         moduleInsertLanguage(LANG_FR, LNG_NUM_STRINGS, langtable_fr);
00258 }
00259 
00260 /* EOF */