summaryrefslogtreecommitdiff
path: root/modules/pseudoclients/botserv.cpp
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2013-07-01 22:17:52 -0400
committerAdam <Adam@anope.org>2013-07-01 22:17:52 -0400
commit1a3d9a016d3adc49788bbff73aac9b3b5ea85b17 (patch)
treec0ecf92ed768473bc82ff64a7fce827245f37ba9 /modules/pseudoclients/botserv.cpp
parent518182ac9204f815258b0de91b3f884d8efa1502 (diff)
Change extensible keys to require explicitly having a type defined for it. Completely modularize more features like bs_kick, entrymsg, log, mode, etc. Move fantasy to its own module. Move greet to its own module.
Diffstat (limited to 'modules/pseudoclients/botserv.cpp')
-rw-r--r--modules/pseudoclients/botserv.cpp138
1 files changed, 8 insertions, 130 deletions
diff --git a/modules/pseudoclients/botserv.cpp b/modules/pseudoclients/botserv.cpp
index 8322ad3c3..e8452de13 100644
--- a/modules/pseudoclients/botserv.cpp
+++ b/modules/pseudoclients/botserv.cpp
@@ -14,9 +14,11 @@
class BotServCore : public Module
{
Reference<BotInfo> BotServ;
+ ExtensibleRef<bool> persist, inhabit;
public:
- BotServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR)
+ BotServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR),
+ persist("persist"), inhabit("inhabit")
{
}
@@ -54,121 +56,6 @@ class BotServCore : public Module
}
}
- void OnPrivmsg(User *u, Channel *c, Anope::string &msg) anope_override
- {
- if (!u || !c || !c->ci || !c->ci->bi || msg.empty())
- return;
-
- /* Answer to ping if needed */
- if (msg.substr(0, 6).equals_ci("\1PING ") && msg[msg.length() - 1] == '\1')
- {
- Anope::string ctcp = msg;
- ctcp.erase(ctcp.begin());
- ctcp.erase(ctcp.length() - 1);
- IRCD->SendCTCP(c->ci->bi, u->nick, "%s", ctcp.c_str());
- }
-
- Anope::string realbuf = msg;
-
- if (realbuf.substr(0, 8).equals_ci("\1ACTION ") && realbuf[realbuf.length() - 1] == '\1')
- {
- realbuf.erase(0, 8);
- realbuf.erase(realbuf.length() - 1);
- return;
- }
-
- if (realbuf.empty() || !c->ci->HasExt("BS_FANTASY"))
- return;
-
- std::vector<Anope::string> params;
- spacesepstream(realbuf).GetTokens(params);
-
- if (!realbuf.find(c->ci->bi->nick))
- params.erase(params.begin());
- else if (!realbuf.find_first_of(Config->GetModule(this)->Get<const Anope::string>("fantasycharacter", "!")))
- params[0].erase(params[0].begin());
- else
- return;
-
- if (params.empty())
- return;
-
- CommandInfo::map::const_iterator it = Config->Fantasy.end();
- unsigned count = 0;
- for (unsigned max = params.size(); it == Config->Fantasy.end() && max > 0; --max)
- {
- Anope::string full_command;
- for (unsigned i = 0; i < max; ++i)
- full_command += " " + params[i];
- full_command.erase(full_command.begin());
-
- ++count;
- it = Config->Fantasy.find(full_command);
- }
-
- if (it == Config->Fantasy.end())
- return;
-
- const CommandInfo &info = it->second;
- ServiceReference<Command> cmd("Command", info.name);
- if (!cmd)
- {
- Log(LOG_DEBUG) << "Fantasy command " << it->first << " exists for nonexistant service " << info.name << "!";
- return;
- }
-
- for (unsigned i = 0, j = params.size() - (count - 1); i < j; ++i)
- params.erase(params.begin());
-
- /* Some commands take the channel as a first parameter */
- if (info.prepend_channel)
- params.insert(params.begin(), c->name);
-
- while (cmd->max_params > 0 && params.size() > cmd->max_params)
- {
- params[cmd->max_params - 1] += " " + params[cmd->max_params];
- params.erase(params.begin() + cmd->max_params);
- }
-
- // Command requires registered users only
- if (!cmd->AllowUnregistered() && !u->Account())
- return;
-
- if (params.size() < cmd->min_params)
- return;
-
- CommandSource source(u->nick, u, u->Account(), u, c->ci->bi);
- source.c = c;
- source.command = it->first;
- source.permission = info.permission;
-
- EventReturn MOD_RESULT;
- if (c->ci->AccessFor(u).HasPriv("FANTASIA"))
- {
- FOREACH_RESULT(OnBotFantasy, MOD_RESULT, (source, cmd, c->ci, params));
- }
- else
- {
- FOREACH_RESULT(OnBotNoFantasyAccess, MOD_RESULT, (source, cmd, c->ci, params));
- }
-
- if (MOD_RESULT == EVENT_STOP || !c->ci->AccessFor(u).HasPriv("FANTASIA"))
- return;
-
- if (MOD_RESULT != EVENT_ALLOW && !info.permission.empty() && !source.HasCommand(info.permission))
- return;
-
- FOREACH_RESULT(OnPreCommand, MOD_RESULT, (source, cmd, params));
- if (MOD_RESULT == EVENT_STOP)
- return;
-
- Reference<NickCore> nc_reference(u->Account());
- cmd->Execute(source, params);
- if (!nc_reference)
- source.nc = NULL;
- FOREACH_MOD(OnPostCommand, (source, cmd, params));
- }
-
void OnJoinChannel(User *user, Channel *c) anope_override
{
if (!Config || !IRCD)
@@ -221,22 +108,13 @@ class BotServCore : public Module
ChannelStatus status(Config->GetModule(this)->Get<const Anope::string>("botmodes"));
c->ci->bi->Join(c, &status);
}
- /* Only display the greet if the main uplink we're connected
- * to has synced, or we'll get greet-floods when the net
- * recovers from a netsplit. -GD
- */
- if (c->FindUser(c->ci->bi) && c->ci->HasExt("BS_GREET") && user->Account() && !user->Account()->greet.empty() && c->ci->AccessFor(user).HasPriv("GREET") && user->server->IsSynced())
- {
- IRCD->SendPrivmsg(c->ci->bi, c->name, "[%s] %s", user->Account()->display.c_str(), user->Account()->greet.c_str());
- c->ci->bi->lastmsg = Anope::CurTime;
- }
}
}
void OnLeaveChannel(User *u, Channel *c) anope_override
{
/* Channel is persistent, it shouldn't be deleted and the service bot should stay */
- if (c->ci && c->ci->HasExt("PERSIST"))
+ if (c->ci && persist && persist->Get(c->ci))
return;
/* Channel is syncing from a netburst, don't destroy it as more users are probably wanting to join immediatly
@@ -246,7 +124,7 @@ class BotServCore : public Module
return;
/* Additionally, do not delete this channel if ChanServ/a BotServ bot is inhabiting it */
- if (c->HasExt("INHABIT"))
+ if (inhabit && inhabit->Get(c))
return;
/* This is called prior to removing the user from the channnel, so c->users.size() - 1 should be safe */
@@ -304,9 +182,9 @@ class BotServCore : public Module
"one of the following characters: %s"), fantasycharacters.c_str());
}
- EventReturn OnChannelModeSet(Channel *c, MessageSource &, const Anope::string &mname, const Anope::string &param) anope_override
+ EventReturn OnChannelModeSet(Channel *c, MessageSource &, ChannelMode *mode, const Anope::string &param) anope_override
{
- if (Config->GetModule(this)->Get<bool>("smartjoin") && mname == "BAN" && c->ci && c->ci->bi && c->FindUser(c->ci->bi))
+ if (Config->GetModule(this)->Get<bool>("smartjoin") && mode->name == "BAN" && c->ci && c->ci->bi && c->FindUser(c->ci->bi))
{
BotInfo *bi = c->ci->bi;
@@ -323,7 +201,7 @@ class BotServCore : public Module
/* Set default bot flags */
spacesepstream sep(Config->GetModule(this)->Get<const Anope::string>("defaults", "greet fantasy"));
for (Anope::string token; sep.GetToken(token);)
- ci->ExtendMetadata("BS_" + token.upper());
+ ci->Extend<bool>("BS_" + token.upper());
}
void OnUserKicked(MessageSource &source, User *target, const Anope::string &channel, ChannelStatus &status, const Anope::string &kickmsg) anope_override