mirror of
https://github.com/anope/anope.git
synced 2026-06-26 21:56:38 +02:00
Make CTCP support more modular.
This commit is contained in:
@@ -41,6 +41,8 @@ public:
|
||||
time_t lastmsg;
|
||||
/* Map of actual command names -> service name/permission required */
|
||||
CommandInfo::map commands;
|
||||
/** CTCP responses this bot can send. */
|
||||
Anope::map<std::function<void(BotInfo *, User *, const Anope::string &)>> ctcps;
|
||||
/* The server-side alias used to message this bot. */
|
||||
Anope::string alias;
|
||||
/* Modes the bot should have as configured in service:modes */
|
||||
|
||||
@@ -34,6 +34,36 @@ BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const A
|
||||
if (!this->uid.empty())
|
||||
(*BotListByUID)[this->uid] = this;
|
||||
|
||||
ctcps.emplace("CLIENTINFO", [this](auto *bi, auto *u, const auto &)
|
||||
{
|
||||
Anope::string buf;
|
||||
for (const auto &[ctcp, _] : this->ctcps)
|
||||
{
|
||||
if (!buf.empty())
|
||||
buf.push_back(' ');
|
||||
buf.append(ctcp.upper());
|
||||
}
|
||||
IRCD->SendNotice(bi, u->GetUID(), Anope::FormatCTCP("CLIENTINFO", buf));
|
||||
});
|
||||
ctcps.emplace("PING", [](auto *bi, auto *u, const auto &ctcpbody)
|
||||
{
|
||||
IRCD->SendNotice(bi, u->GetUID(), Anope::FormatCTCP("PING", ctcpbody));
|
||||
});
|
||||
ctcps.emplace("SOURCE", [](auto *bi, auto *u, const auto &)
|
||||
{
|
||||
IRCD->SendNotice(bi, u->GetUID(), Anope::FormatCTCP("SOURCE", "https://www.anope.org/"));
|
||||
});
|
||||
ctcps.emplace("TIME", [](auto *bi, auto *u, const auto &)
|
||||
{
|
||||
IRCD->SendNotice(bi, u->GetUID(), Anope::FormatCTCP("TIME", Anope::strftime(Anope::CurTime, nullptr, true)));
|
||||
});
|
||||
ctcps.emplace("VERSION", [](auto *bi, auto *u, const auto &)
|
||||
{
|
||||
auto *enc = ModuleManager::FindFirstOf(ENCRYPTION);
|
||||
IRCD->SendNotice(bi, u->GetUID(), Anope::FormatCTCP("VERSION", Anope::printf("Anope-%s %s -- %s -- %s", Anope::Version().c_str(),
|
||||
Anope::VersionBuildString().c_str(), IRCD->GetProtocolName().c_str(), enc ? enc->name.c_str() : "(none)")));
|
||||
});
|
||||
|
||||
FOREACH_MOD(OnCreateBot, (this));
|
||||
|
||||
// If we're synchronised with the uplink already, send the bot.
|
||||
|
||||
+3
-10
@@ -340,16 +340,9 @@ void Privmsg::Run(MessageSource &source, const std::vector<Anope::string> ¶m
|
||||
Anope::string ctcpname, ctcpbody;
|
||||
if (Anope::ParseCTCP(message, ctcpname, ctcpbody))
|
||||
{
|
||||
if (ctcpname.equals_ci("PING"))
|
||||
{
|
||||
IRCD->SendNotice(bi, u->nick, Anope::FormatCTCP("PING", ctcpbody));
|
||||
}
|
||||
else if (ctcpname.equals_ci("VERSION"))
|
||||
{
|
||||
Module *enc = ModuleManager::FindFirstOf(ENCRYPTION);
|
||||
IRCD->SendNotice(bi, u->nick, Anope::FormatCTCP("VERSION", Anope::printf("Anope-%s %s -- %s -- %s", Anope::Version().c_str(),
|
||||
Anope::VersionBuildString().c_str(), IRCD->GetProtocolName().c_str(), enc ? enc->name.c_str() : "(none)")));
|
||||
}
|
||||
auto ctcpit = bi->ctcps.find(ctcpname);
|
||||
if (ctcpit != bi->ctcps.end())
|
||||
ctcpit->second(bi, u, ctcpbody);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user