summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSadie Powell <sadie@witchery.services>2025-05-10 14:15:27 +0100
committerSadie Powell <sadie@witchery.services>2025-05-27 15:30:09 +0100
commit50030e07fa51d3e8970ca044bf745f513501bfee (patch)
tree01eb1ac77e61314301688af9c081e46abcda9f38 /src
parent7b2f0f579016f2d8cc8c919704cf1f75d74558db (diff)
Make CTCP support more modular.HEAD2.1
Diffstat (limited to 'src')
-rw-r--r--src/bots.cpp30
-rw-r--r--src/messages.cpp13
2 files changed, 33 insertions, 10 deletions
diff --git a/src/bots.cpp b/src/bots.cpp
index 3c203849f..6db542dd3 100644
--- a/src/bots.cpp
+++ b/src/bots.cpp
@@ -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.
diff --git a/src/messages.cpp b/src/messages.cpp
index 2ed52b3e7..ec2b255f8 100644
--- a/src/messages.cpp
+++ b/src/messages.cpp
@@ -340,16 +340,9 @@ void Privmsg::Run(MessageSource &source, const std::vector<Anope::string> &param
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;
}