cs_appendtopic.cpp

Go to the documentation of this file.
00001 /* cs_appendtopic.c - Add text to a channels topic
00002  *
00003  * (C) 2003-2012 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 /* ------------------------------------------------------------
00022  * Name: cs_appendtopic
00023  * Author: SGR <Alex_SGR@ntlworld.com>
00024  * Date: 31/08/2003
00025  * ------------------------------------------------------------
00026  *
00027  * This module has no configurable options. For information on
00028  * this module, load it and refer to /ChanServ APPENDTOPIC HELP
00029  *
00030  * Thanks to dengel, Rob and Certus for all there support.
00031  * Especially Rob, who always manages to show me where I have
00032  * not allocated any memory. Even if it takes a few weeks of
00033  * pestering to get him to look at it.
00034  *
00035  * ------------------------------------------------------------
00036  */
00037 
00038 /* ---------------------------------------------------------------------- */
00039 /* DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING         */
00040 /* ---------------------------------------------------------------------- */
00041 
00042 class CommandCSAppendTopic : public Command
00043 {
00044  public:
00045         CommandCSAppendTopic(Module *creator) : Command(creator, "chanserv/appendtopic", 2, 2)
00046         {
00047                 this->SetDesc(_("Add text to a channels topic"));
00048                 this->SetSyntax(_("\037channel\037 \037text\037"));
00049         }
00050 
00051         void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
00052         {
00053                 const Anope::string &newtopic = params[1];
00054 
00055                 Channel *c = Channel::Find(params[0]);;
00056 
00057                 if (!c)
00058                         source.Reply(CHAN_X_NOT_IN_USE, params[0].c_str());
00059                 else if (!c->ci)
00060                         source.Reply(CHAN_X_NOT_REGISTERED, c->name.c_str());
00061                 else if (!source.AccessFor(c->ci).HasPriv("TOPIC") && !source.HasCommand("chanserv/topic"))
00062                         source.Reply(ACCESS_DENIED);
00063                 else
00064                 {
00065                         Anope::string topic;
00066                         if (!c->ci->last_topic.empty())
00067                         {
00068                                 topic = c->ci->last_topic + " " + newtopic;
00069                                 c->ci->last_topic.clear();
00070                         }
00071                         else
00072                                 topic = newtopic;
00073 
00074                         bool has_topiclock = c->ci->HasFlag(CI_TOPICLOCK);
00075                         c->ci->UnsetFlag(CI_TOPICLOCK);
00076                         c->ChangeTopic(source.GetNick(), topic, Anope::CurTime);
00077                         if (has_topiclock)
00078                                 c->ci->SetFlag(CI_TOPICLOCK);
00079 
00080                         bool override = !source.AccessFor(c->ci).HasPriv("TOPIC");
00081                         Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, c->ci) << "to append: " << topic;
00082                 }
00083                 return;
00084         }
00085 
00086         bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
00087         {
00088                 this->SendSyntax(source);
00089                 source.Reply(" ");
00090                 source.Reply(_("This command allows users to append text to a currently set\n"
00091                         "channel topic. When TOPICLOCK is on, the topic is updated and\n"
00092                         "the new, updated topic is locked."));
00093 
00094                 return true;
00095         }
00096 };
00097 
00098 class CSAppendTopic : public Module
00099 {
00100         CommandCSAppendTopic commandcsappendtopic;
00101 
00102  public:
00103         CSAppendTopic(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE),
00104                 commandcsappendtopic(this)
00105         {
00106                 this->SetAuthor("SGR");
00107 
00108         }
00109 };
00110 
00111 MODULE_INIT(CSAppendTopic)