diff options
| author | Adam <Adam@anope.org> | 2012-12-27 09:43:19 -0500 |
|---|---|---|
| committer | Adam <Adam@anope.org> | 2012-12-27 09:43:19 -0500 |
| commit | 7b1ae9602d0aa3053814c7d1e6f460860f5180e0 (patch) | |
| tree | 27245ce4d1754ac3fe294dbb5bfe3c42b599280c /modules | |
| parent | c7a22dff878cc517a34d36767df0edd77fd72c09 (diff) | |
Put appendtopic and topiclock into /cs topic
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/commands/cs_appendtopic.cpp | 111 | ||||
| -rw-r--r-- | modules/commands/cs_set.cpp | 59 | ||||
| -rw-r--r-- | modules/commands/cs_topic.cpp | 99 |
3 files changed, 71 insertions, 198 deletions
diff --git a/modules/commands/cs_appendtopic.cpp b/modules/commands/cs_appendtopic.cpp deleted file mode 100644 index 2d7c0f278..000000000 --- a/modules/commands/cs_appendtopic.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/* cs_appendtopic.c - Add text to a channels topic - * - * (C) 2003-2012 Anope Team - * Contact us at team@anope.org - * - * Based on the original module by SGR <Alex_SGR@ntlworld.com> - * Included in the Anope module pack since Anope 1.7.9 - * Anope Coder: GeniusDex <geniusdex@anope.org> - * - * Please read COPYING and README for further details. - * - * Send bug reports to the Anope Coder instead of the module - * author, because any changes since the inclusion into anope - * are not supported by the original author. - */ - -/*************************************************************************/ - -#include "module.h" - -/* ------------------------------------------------------------ - * Name: cs_appendtopic - * Author: SGR <Alex_SGR@ntlworld.com> - * Date: 31/08/2003 - * ------------------------------------------------------------ - * - * This module has no configurable options. For information on - * this module, load it and refer to /ChanServ APPENDTOPIC HELP - * - * Thanks to dengel, Rob and Certus for all there support. - * Especially Rob, who always manages to show me where I have - * not allocated any memory. Even if it takes a few weeks of - * pestering to get him to look at it. - * - * ------------------------------------------------------------ - */ - -/* ---------------------------------------------------------------------- */ -/* DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING */ -/* ---------------------------------------------------------------------- */ - -class CommandCSAppendTopic : public Command -{ - public: - CommandCSAppendTopic(Module *creator) : Command(creator, "chanserv/appendtopic", 2, 2) - { - this->SetDesc(_("Add text to a channels topic")); - this->SetSyntax(_("\037channel\037 \037text\037")); - } - - void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - const Anope::string &newtopic = params[1]; - - Channel *c = Channel::Find(params[0]);; - - if (!c) - source.Reply(CHAN_X_NOT_IN_USE, params[0].c_str()); - else if (!c->ci) - source.Reply(CHAN_X_NOT_REGISTERED, c->name.c_str()); - else if (!source.AccessFor(c->ci).HasPriv("TOPIC") && !source.HasCommand("chanserv/topic")) - source.Reply(ACCESS_DENIED); - else - { - Anope::string topic; - if (!c->ci->last_topic.empty()) - { - topic = c->ci->last_topic + " " + newtopic; - c->ci->last_topic.clear(); - } - else - topic = newtopic; - - bool has_topiclock = c->ci->HasFlag(CI_TOPICLOCK); - c->ci->UnsetFlag(CI_TOPICLOCK); - c->ChangeTopic(source.GetNick(), topic, Anope::CurTime); - if (has_topiclock) - c->ci->SetFlag(CI_TOPICLOCK); - - bool override = !source.AccessFor(c->ci).HasPriv("TOPIC"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, c->ci) << "to append: " << topic; - } - return; - } - - bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override - { - this->SendSyntax(source); - source.Reply(" "); - source.Reply(_("This command allows users to append text to a currently set\n" - "channel topic. When TOPICLOCK is on, the topic is updated and\n" - "the new, updated topic is locked.")); - - return true; - } -}; - -class CSAppendTopic : public Module -{ - CommandCSAppendTopic commandcsappendtopic; - - public: - CSAppendTopic(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE), - commandcsappendtopic(this) - { - this->SetAuthor("SGR"); - - } -}; - -MODULE_INIT(CSAppendTopic) diff --git a/modules/commands/cs_set.cpp b/modules/commands/cs_set.cpp index ecd228877..5ac235c8f 100644 --- a/modules/commands/cs_set.cpp +++ b/modules/commands/cs_set.cpp @@ -1084,62 +1084,6 @@ class CommandCSSetSuccessor : public Command } }; -class CommandCSSetTopicLock : public Command -{ - public: - CommandCSSetTopicLock(Module *creator, const Anope::string &cname = "chanserv/set/topiclock") : Command(creator, cname, 2, 2) - { - this->SetDesc(_("Topic can only be changed with TOPIC")); - this->SetSyntax(_("\037channel\037 {ON | OFF}")); - } - - void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - ChannelInfo *ci = ChannelInfo::Find(params[0]); - if (ci == NULL) - { - source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); - return; - } - - EventReturn MOD_RESULT; - FOREACH_RESULT(I_OnSetChannelOption, OnSetChannelOption(source, this, ci, params[1])); - if (MOD_RESULT == EVENT_STOP) - return; - - if (MOD_RESULT != EVENT_ALLOW && source.permission.empty() && !source.AccessFor(ci).HasPriv("SET")) - { - source.Reply(ACCESS_DENIED); - return; - } - - if (params[1].equals_ci("ON")) - { - ci->SetFlag(CI_TOPICLOCK); - source.Reply(_("Topic lock option for %s is now \002on\002."), ci->name.c_str()); - } - else if (params[1].equals_ci("OFF")) - { - ci->UnsetFlag(CI_TOPICLOCK); - source.Reply(_("Topic lock option for %s is now \002off\002."), ci->name.c_str()); - } - else - this->OnSyntaxError(source, "TOPICLOCK"); - - return; - } - - bool OnHelp(CommandSource &source, const Anope::string &) anope_override - { - this->SendSyntax(source); - source.Reply(" "); - source.Reply(_("Enables or disables the \002topic lock\002 option for a channel.\n" - "When \002topic lock\002 is set, the channel topic will be unchangable\n" - "except via the \002TOPIC\002 command.")); - return true; - } -}; - class CommandCSSASetNoexpire : public Command { public: @@ -1210,7 +1154,6 @@ class CSSet : public Module CommandCSSetSecureOps commandcssetsecureops; CommandCSSetSignKick commandcssetsignkick; CommandCSSetSuccessor commandcssetsuccessor; - CommandCSSetTopicLock commandcssettopiclock; CommandCSSASetNoexpire commandcssasetnoexpire; public: @@ -1219,7 +1162,7 @@ class CSSet : public Module CSDefChanstats(false), commandcssetdescription(this), commandcssetfounder(this), commandcssetkeeptopic(this), commandcssetpeace(this), commandcssetpersist(this), commandcssetprivate(this), commandcssetrestricted(this), commandcssetsecure(this), commandcssetsecurefounder(this), commandcssetsecureops(this), commandcssetsignkick(this), - commandcssetsuccessor(this), commandcssettopiclock(this), commandcssasetnoexpire(this) + commandcssetsuccessor(this), commandcssasetnoexpire(this) { this->SetAuthor("Anope"); diff --git a/modules/commands/cs_topic.cpp b/modules/commands/cs_topic.cpp index eccb8b2f6..1356668f9 100644 --- a/modules/commands/cs_topic.cpp +++ b/modules/commands/cs_topic.cpp @@ -9,59 +9,100 @@ * Based on the original code of Services by Andy Church. */ -/*************************************************************************/ - #include "module.h" class CommandCSTopic : public Command { + void Lock(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) + { + ci->SetFlag(CI_TOPICLOCK); + source.Reply(_("Topic lock option for %s is now \002on\002."), ci->name.c_str()); + } + + void Unlock(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) + { + ci->UnsetFlag(CI_TOPICLOCK); + source.Reply(_("Topic lock option for %s is now \002off\002."), ci->name.c_str()); + } + + void Set(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) + { + const Anope::string &topic = params.size() > 2 ? params[2] : ""; + + bool has_topiclock = ci->HasFlag(CI_TOPICLOCK); + ci->UnsetFlag(CI_TOPICLOCK); + ci->c->ChangeTopic(source.GetNick(), topic, Anope::CurTime); + if (has_topiclock) + ci->SetFlag(CI_TOPICLOCK); + + bool override = !source.AccessFor(ci).HasPriv("TOPIC"); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << (!topic.empty() ? "to change the topic to: " : "to unset the topic") << (!topic.empty() ? topic : ""); + } + + void Append(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) + { + const Anope::string &topic = params[2]; + + Anope::string new_topic; + if (!ci->c->topic.empty()) + { + new_topic = ci->c->topic + " " + topic; + ci->last_topic.clear(); + } + else + new_topic = topic; + + std::vector<Anope::string> new_params; + new_params.push_back("SET"); + new_params.push_back(ci->name); + new_params.push_back(new_topic); + + this->Set(source, ci, new_params); + } + public: - CommandCSTopic(Module *creator) : Command(creator, "chanserv/topic", 1, 2) + CommandCSTopic(Module *creator) : Command(creator, "chanserv/topic", 2, 3) { this->SetDesc(_("Manipulate the topic of the specified channel")); - this->SetSyntax(_("\037channel\037 [\037topic\037]")); + this->SetSyntax(_("\037channel\037 SET [\037topic\037]")); + this->SetSyntax(_("\037channel\037 APPEND \037topic\037")); + this->SetSyntax(_("\037channel\037 [UNLOCK|LOCK]")); } void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override { - const Anope::string &topic = params.size() > 1 ? params[1] : ""; - + const Anope::string &subcmd = params[1]; ChannelInfo *ci = ChannelInfo::Find(params[0]); if (ci == NULL) - { source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); - return; - } - - if (!ci->c) - source.Reply(CHAN_X_NOT_IN_USE, ci->name.c_str()); else if (!source.AccessFor(ci).HasPriv("TOPIC") && !source.HasCommand("chanserv/topic")) source.Reply(ACCESS_DENIED); + else if (subcmd.equals_ci("LOCK")) + this->Lock(source, ci, params); + else if (subcmd.equals_ci("UNLOCK")) + this->Unlock(source, ci, params); + else if (!ci->c) + source.Reply(CHAN_X_NOT_IN_USE, ci->name.c_str()); + else if (subcmd.equals_ci("SET")) + this->Set(source, ci, params); + else if (subcmd.equals_ci("APPEND") && params.size() > 2) + this->Append(source, ci, params); else - { - bool has_topiclock = ci->HasFlag(CI_TOPICLOCK); - ci->UnsetFlag(CI_TOPICLOCK); - ci->c->ChangeTopic(source.GetNick(), topic, Anope::CurTime); - if (has_topiclock) - ci->SetFlag(CI_TOPICLOCK); - - bool override = !source.AccessFor(ci).HasPriv("TOPIC"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << (!topic.empty() ? "to change the topic to: " : "to unset the topic") << (!topic.empty() ? topic : ""); - } - return; + this->SendSyntax(source); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override { this->SendSyntax(source); source.Reply(" "); - source.Reply(_("Causes %s to set the channel topic to the one\n" - "specified. If \002topic\002 is not given, then an empty topic\n" - "is set. This command is most useful in conjunction\n" - "with topic lock.\n" - "By default, limited to those with founder access on the\n" - "channel."), source.service->nick.c_str()); + source.Reply(_("Allows manipulating the topic of the specified channel.\n" + "The \2SET\2 command changes the topic of the channel to the given topic\n" + "or unsets the topic if no topic is given. The \2APPEND\2 command appends\n" + "the given topic to the existing topic.\n" + " \n" + "\2LOCK\2 and \2UNLOCK\2 may be used to enable and disable topic lock. When\n" + "topic lock is set, the channel topic will be unchangable except via this command.")); return true; } }; |
