summaryrefslogtreecommitdiff
path: root/modules/fantasy.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/fantasy.cpp')
-rw-r--r--modules/fantasy.cpp97
1 files changed, 54 insertions, 43 deletions
diff --git a/modules/fantasy.cpp b/modules/fantasy.cpp
index 7f17247fc..9c6a50664 100644
--- a/modules/fantasy.cpp
+++ b/modules/fantasy.cpp
@@ -1,15 +1,25 @@
-/* Fantasy functionality
+/*
+ * Anope IRC Services
*
- * (C) 2003-2017 Anope Team
- * Contact us at team@anope.org
+ * Copyright (C) 2013-2017 Anope Team <team@anope.org>
*
- * Please read COPYING and README for further details.
+ * This file is part of Anope. Anope is free software; you can
+ * redistribute it and/or modify it under the terms of the GNU
+ * General Public License as published by the Free Software
+ * Foundation, version 2.
*
- * Based on the original code of Epona by Lara.
- * Based on the original code of Services by Andy Church.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see see <http://www.gnu.org/licenses/>.
*/
#include "module.h"
+#include "modules/fantasy.h"
+#include "modules/botserv/info.h"
class CommandBSSetFantasy : public Command
{
@@ -20,20 +30,20 @@ class CommandBSSetFantasy : public Command
this->SetSyntax(_("\037channel\037 {\037ON|OFF\037}"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
- ChannelInfo *ci = ChannelInfo::Find(params[0]);
+ ChanServ::Channel *ci = ChanServ::Find(params[0]);
const Anope::string &value = params[1];
if (ci == NULL)
{
- source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str());
+ source.Reply(_("Channel \002{0}\002 isn't registered."), params[0]);
return;
}
- if (!source.HasPriv("botserv/administration") && !source.AccessFor(ci).HasPriv("SET"))
+ if (!source.AccessFor(ci).HasPriv("SET") && !source.HasPriv("botserv/administration"))
{
- source.Reply(ACCESS_DENIED);
+ source.Reply(_("Access denied. You do not have the \002{0}\002 privilege on \002{1}\002."), "SET", ci->GetName());
return;
}
@@ -45,25 +55,25 @@ class CommandBSSetFantasy : public Command
if (value.equals_ci("ON"))
{
- bool override = !source.AccessFor(ci).HasPriv("SET");
- Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to enable fantasy";
+ logger.Command(source, ci, _("{source} used {command} on {channel} to enable fantasy"));
- ci->Extend<bool>("BS_FANTASY");
- source.Reply(_("Fantasy mode is now \002on\002 on channel %s."), ci->name.c_str());
+ ci->SetFantasy(true);
+ source.Reply(_("Fantasy mode is now \002on\002 on channel \002{0}\002."), ci->GetName());
}
else if (value.equals_ci("OFF"))
{
- bool override = !source.AccessFor(ci).HasPriv("SET");
- Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to disable fantasy";
+ logger.Command(source, ci, _("{source} used {command} on {channel} to disable fantasy"));
- ci->Shrink<bool>("BS_FANTASY");
- source.Reply(_("Fantasy mode is now \002off\002 on channel %s."), ci->name.c_str());
+ ci->SetFantasy(false);
+ source.Reply(_("Fantasy mode is now \002off\002 on channel \002{0}\002."), ci->GetName());
}
else
- this->OnSyntaxError(source, source.command);
+ {
+ this->OnSyntaxError(source, source.GetCommand());
+ }
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
this->SendSyntax(source);
source.Reply(_(" \n"
@@ -75,29 +85,31 @@ class CommandBSSetFantasy : public Command
"Note that users wanting to use fantaisist\n"
"commands MUST have enough access for both\n"
"the FANTASIA and the command they are executing."),
- Config->GetModule(this->owner)->Get<const Anope::string>("fantasycharacter", "!").c_str());
+ Config->GetModule(this->GetOwner())->Get<Anope::string>("fantasycharacter", "!").c_str());
return true;
}
};
class Fantasy : public Module
+ , public EventHook<Event::Privmsg>
+ , public EventHook<Event::ServiceBotEvent>
{
- SerializableExtensibleItem<bool> fantasy;
-
CommandBSSetFantasy commandbssetfantasy;
public:
- Fantasy(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
- fantasy(this, "BS_FANTASY"), commandbssetfantasy(this)
+ Fantasy(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , EventHook<Event::Privmsg>(this)
+ , EventHook<Event::ServiceBotEvent>(this)
+ , commandbssetfantasy(this)
{
}
- void OnPrivmsg(User *u, Channel *c, Anope::string &msg) anope_override
+ void OnPrivmsg(User *u, Channel *c, Anope::string &msg) override
{
- if (!u || !c || !c->ci || !c->ci->bi || msg.empty() || msg[0] == '\1')
+ if (!u || !c || !c->ci || !c->ci->GetBot() || msg.empty() || msg[0] == '\1')
return;
- if (Config->GetClient("BotServ") && !fantasy.HasExt(c->ci))
+ if (Config->GetClient("BotServ") && !c->ci->IsFantasy())
return;
std::vector<Anope::string> params;
@@ -109,7 +121,7 @@ class Fantasy : public Module
Anope::string normalized_param0 = Anope::NormalizeBuffer(params[0]);
Anope::string fantasy_chars = Config->GetModule(this)->Get<Anope::string>("fantasycharacter", "!");
- if (!normalized_param0.find(c->ci->bi->nick))
+ if (!normalized_param0.find(c->ci->GetBot()->nick))
{
params.erase(params.begin());
}
@@ -146,10 +158,10 @@ class Fantasy : public Module
return;
const CommandInfo &info = it->second;
- ServiceReference<Command> cmd("Command", info.name);
+ ServiceReference<Command> cmd(info.name);
if (!cmd)
{
- Log(LOG_DEBUG) << "Fantasy command " << it->first << " exists for non-existent service " << info.name << "!";
+ logger.Debug("Fantasy command {0} exists for non-existent service {1}!", it->first, info.name);
return;
}
@@ -173,22 +185,21 @@ class Fantasy : public Module
if (params.size() < cmd->min_params)
return;
- CommandSource source(u->nick, u, u->Account(), u, c->ci->bi);
+ CommandSource source(u->nick, u, u->Account(), u, c->ci->GetBot());
source.c = c;
- source.command = it->first;
- source.permission = info.permission;
+ source.SetCommandInfo(info);
- AccessGroup ag = c->ci->AccessFor(u);
+ ChanServ::AccessGroup ag = c->ci->AccessFor(u);
bool has_fantasia = ag.HasPriv("FANTASIA") || source.HasPriv("botserv/fantasy");
EventReturn MOD_RESULT;
if (has_fantasia)
{
- FOREACH_RESULT(OnBotFantasy, MOD_RESULT, (source, cmd, c->ci, params));
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::BotFantasy::OnBotFantasy, source, cmd, c->ci, params);
}
else
{
- FOREACH_RESULT(OnBotNoFantasyAccess, MOD_RESULT, (source, cmd, c->ci, params));
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::BotNoFantasyAccess::OnBotNoFantasyAccess, source, cmd, c->ci, params);
}
if (MOD_RESULT == EVENT_STOP || !has_fantasia)
@@ -197,20 +208,20 @@ class Fantasy : public Module
if (MOD_RESULT != EVENT_ALLOW && !info.permission.empty() && !source.HasCommand(info.permission))
return;
- FOREACH_RESULT(OnPreCommand, MOD_RESULT, (source, cmd, params));
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::PreCommand::OnPreCommand, source, cmd, params);
if (MOD_RESULT == EVENT_STOP)
return;
- Reference<NickCore> nc_reference(u->Account());
+ Reference<NickServ::Account> nc_reference(u->Account());
cmd->Execute(source, params);
if (!nc_reference)
source.nc = NULL;
- FOREACH_MOD(OnPostCommand, (source, cmd, params));
+ EventManager::Get()->Dispatch(&Event::PostCommand::OnPostCommand, source, cmd, params);
}
- void OnBotInfo(CommandSource &source, BotInfo *bi, ChannelInfo *ci, InfoFormatter &info)
+ void OnServiceBot(CommandSource &source, ServiceBot *bi, ChanServ::Channel *ci, InfoFormatter &info) override
{
- if (fantasy.HasExt(ci))
+ if (ci->IsFantasy())
info.AddOption(_("Fantasy"));
}
};