summaryrefslogtreecommitdiff
path: root/modules/commands/cs_topic.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/commands/cs_topic.cpp')
-rw-r--r--modules/commands/cs_topic.cpp109
1 files changed, 60 insertions, 49 deletions
diff --git a/modules/commands/cs_topic.cpp b/modules/commands/cs_topic.cpp
index bc5b9c000..03a2fb0d5 100644
--- a/modules/commands/cs_topic.cpp
+++ b/modules/commands/cs_topic.cpp
@@ -11,6 +11,8 @@
#include "module.h"
#include "modules/cs_mode.h"
+#include "modules/cs_info.h"
+#include "modules/cs_set.h"
class CommandCSSetKeepTopic : public Command
{
@@ -21,57 +23,56 @@ class CommandCSSetKeepTopic : public Command
this->SetSyntax(_("\037channel\037 {ON | OFF}"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
+ const Anope::string &chan = params[0];
+ const Anope::string &param = params[1];
+
if (Anope::ReadOnly)
{
- source.Reply(READ_ONLY_MODE);
+ source.Reply(_("Services are in read-only mode."));
return;
}
- ChannelInfo *ci = ChannelInfo::Find(params[0]);
+ ChanServ::Channel *ci = ChanServ::Find(chan);
if (ci == NULL)
{
- source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str());
+ source.Reply(_("Channel \002{0}\002 isn't registered."), chan);
return;
}
EventReturn MOD_RESULT;
- FOREACH_RESULT(OnSetChannelOption, MOD_RESULT, (source, this, ci, params[1]));
+ MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param);
if (MOD_RESULT == EVENT_STOP)
return;
if (MOD_RESULT != EVENT_ALLOW && !source.AccessFor(ci).HasPriv("SET") && source.permission.empty() && !source.HasPriv("chanserv/administration"))
{
- source.Reply(ACCESS_DENIED);
+ source.Reply(_("Access denied. You do not have privilege \002{0}\002 on \002{1}\002."), "SET", ci->name);
return;
}
- if (params[1].equals_ci("ON"))
+ if (param.equals_ci("ON"))
{
Log(source.AccessFor(ci).HasPriv("SET") ? LOG_COMMAND : LOG_OVERRIDE, source, this, ci) << "to enable keeptopic";
ci->Extend<bool>("KEEPTOPIC");
- source.Reply(_("Topic retention option for %s is now \002on\002."), ci->name.c_str());
+ source.Reply(_("Topic retention option for \002{0}\002 is now \002on\002."), ci->name);
}
- else if (params[1].equals_ci("OFF"))
+ else if (param.equals_ci("OFF"))
{
Log(source.AccessFor(ci).HasPriv("SET") ? LOG_COMMAND : LOG_OVERRIDE, source, this, ci) << "to disable keeptopic";
ci->Shrink<bool>("KEEPTOPIC");
- source.Reply(_("Topic retention option for %s is now \002off\002."), ci->name.c_str());
+ source.Reply(_("Topic retention option for \002{0}\002 is now \002off\002."), ci->name);
}
else
this->OnSyntaxError(source, "KEEPTOPIC");
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
- this->SendSyntax(source);
- source.Reply(" ");
- source.Reply(_("Enables or disables the \002topic retention\002 option for a\n"
- "channel. When \002%s\002 is set, the topic for the\n"
- "channel will be remembered by %s even after the\n"
- "last user leaves the channel, and will be restored the\n"
- "next time the channel is created."), source.command.c_str(), source.service->nick.c_str());
+ source.Reply(_("Enables or disables the \002topic retention\002 option for a \037channel\037."
+ " When \002topic retention\002 is set, the topic for the channel will be remembered by {0} even after the last user leaves the channel, and will be restored the next time the channel is created."),
+ source.service->nick);
return true;
}
};
@@ -80,41 +81,41 @@ class CommandCSTopic : public Command
{
ExtensibleRef<bool> topiclock;
- void Lock(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> &params)
+ void Lock(CommandSource &source, ChanServ::Channel *ci, const std::vector<Anope::string> &params)
{
if (Anope::ReadOnly)
{
- source.Reply(READ_ONLY_MODE);
+ source.Reply(_("Services are in read-only mode."));
return;
}
EventReturn MOD_RESULT;
- FOREACH_RESULT(OnSetChannelOption, MOD_RESULT, (source, this, ci, "topiclock on"));
+ MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, "topiclock on");
if (MOD_RESULT == EVENT_STOP)
return;
topiclock->Set(ci, true);
- source.Reply(_("Topic lock option for %s is now \002on\002."), ci->name.c_str());
+ source.Reply(_("Topic lock option for \002{0}\002 is now \002on\002."), ci->name);
}
- void Unlock(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> &params)
+ void Unlock(CommandSource &source, ChanServ::Channel *ci, const std::vector<Anope::string> &params)
{
if (Anope::ReadOnly)
{
- source.Reply(READ_ONLY_MODE);
+ source.Reply(_("Services are in read-only mode."));
return;
}
EventReturn MOD_RESULT;
- FOREACH_RESULT(OnSetChannelOption, MOD_RESULT, (source, this, ci, "topiclock off"));
+ MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, "topiclock off");
if (MOD_RESULT == EVENT_STOP)
return;
topiclock->Unset(ci);
- source.Reply(_("Topic lock option for %s is now \002off\002."), ci->name.c_str());
+ source.Reply(_("Topic lock option for \002{0}\002 is now \002off\002."), ci->name);
}
- void Set(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> &params)
+ void Set(CommandSource &source, ChanServ::Channel *ci, const std::vector<Anope::string> &params)
{
const Anope::string &topic = params.size() > 2 ? params[2] : "";
@@ -123,12 +124,12 @@ class CommandCSTopic : public Command
ci->c->ChangeTopic(source.GetNick(), topic, Anope::CurTime);
if (has_topiclock)
topiclock->Set(ci);
-
+
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> &params)
+ void Append(CommandSource &source, ChanServ::Channel *ci, const std::vector<Anope::string> &params)
{
const Anope::string &topic = params[2];
@@ -159,21 +160,22 @@ class CommandCSTopic : public Command
this->SetSyntax(_("\037channel\037 [UNLOCK|LOCK]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
+ const Anope::string &channel = params[0];
const Anope::string &subcmd = params[1];
- ChannelInfo *ci = ChannelInfo::Find(params[0]);
+ ChanServ::Channel *ci = ChanServ::Find(channel);
if (ci == NULL)
- source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str());
+ source.Reply(_("Channel \002{0}\002 isn't registered."), channel);
else if (!source.AccessFor(ci).HasPriv("TOPIC") && !source.HasCommand("chanserv/topic"))
- source.Reply(ACCESS_DENIED);
+ source.Reply(_("Access denied. You do not have privilege \002{0}\002 on \002{1}\002."), "TOPIC", ci->name);
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());
+ source.Reply(_("Channel \002{0}\002 doesn't exist."), ci->name);
else if (subcmd.equals_ci("SET"))
this->Set(source, ci, params);
else if (subcmd.equals_ci("APPEND") && params.size() > 2)
@@ -182,22 +184,25 @@ class CommandCSTopic : public Command
this->SendSyntax(source);
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
- this->SendSyntax(source);
- source.Reply(" ");
- source.Reply(_("Allows manipulating the topic of the specified channel.\n"
- "The \002SET\002 command changes the topic of the channel to the given topic\n"
- "or unsets the topic if no topic is given. The \002APPEND\002 command appends\n"
- "the given topic to the existing topic.\n"
- " \n"
- "\002LOCK\002 and \002UNLOCK\002 may be used to enable and disable topic lock. When\n"
- "topic lock is set, the channel topic will be unchangeable except via this command."));
+ source.Reply(_("Allows manipulating the topic of the specified channel."
+ " The \002SET\002 command changes the topic of the channel to the given topic or unsets the topic if no topic is given."
+ " The \002APPEND\002 command appends the given topic to the existing topic.\n"
+ "\n"
+ "\002LOCK\002 and \002UNLOCK\002 may be used to enable and disable topic lock."
+ " When topic lock is set, the channel topic will be unchangeable except via this command.\n"
+ "\n"
+ "Use of this command requires the \002{0}\002 privilege on \037channel\037."),
+ "TOPIC");
return true;
}
};
class CSTopic : public Module
+ , public EventHook<Event::ChannelSync>
+ , public EventHook<Event::TopicUpdated>
+ , public EventHook<Event::ChanInfo>
{
CommandCSTopic commandcstopic;
CommandCSSetKeepTopic commandcssetkeeptopic;
@@ -205,13 +210,19 @@ class CSTopic : public Module
SerializableExtensibleItem<bool> topiclock, keeptopic;
public:
- CSTopic(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
- commandcstopic(this), commandcssetkeeptopic(this), topiclock(this, "TOPICLOCK"), keeptopic(this, "KEEPTOPIC")
+ CSTopic(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , EventHook<Event::ChannelSync>("OnChannelSync")
+ , EventHook<Event::TopicUpdated>("OnTopicUpdated")
+ , EventHook<Event::ChanInfo>("OnChanInfo")
+ , commandcstopic(this)
+ , commandcssetkeeptopic(this)
+ , topiclock(this, "TOPICLOCK")
+ , keeptopic(this, "KEEPTOPIC")
{
}
- void OnChannelSync(Channel *c) anope_override
+ void OnChannelSync(Channel *c) override
{
if (c->ci)
{
@@ -223,7 +234,7 @@ class CSTopic : public Module
}
}
- void OnTopicUpdated(Channel *c, const Anope::string &user, const Anope::string &topic) anope_override
+ void OnTopicUpdated(Channel *c, const Anope::string &user, const Anope::string &topic) override
{
if (!c->ci)
return;
@@ -245,7 +256,7 @@ class CSTopic : public Module
}
}
- void OnChanInfo(CommandSource &source, ChannelInfo *ci, InfoFormatter &info, bool show_all) anope_override
+ void OnChanInfo(CommandSource &source, ChanServ::Channel *ci, InfoFormatter &info, bool show_all) override
{
if (keeptopic.HasExt(ci))
info.AddOption(_("Topic retention"));