diff options
author | Sadie Powell <sadie@witchery.services> | 2025-04-14 11:31:19 +0100 |
---|---|---|
committer | Sadie Powell <sadie@witchery.services> | 2025-04-14 11:31:19 +0100 |
commit | d04a312d0d1edd1223b55ed89b7fb707ceca3117 (patch) | |
tree | 39b0c165b17d5ff4571423b2bc279b34546c3b72 /modules | |
parent | 099f0ce43a7e34e4a6e74d91aa911c745c262ba8 (diff) |
Add Anope::Templace and switch all template strings to use it.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/chanserv/cs_akick.cpp | 6 | ||||
-rw-r--r-- | modules/chanserv/cs_ban.cpp | 13 | ||||
-rw-r--r-- | modules/chanserv/cs_kick.cpp | 13 | ||||
-rw-r--r-- | modules/dnsbl.cpp | 18 | ||||
-rw-r--r-- | modules/ldap_authentication.cpp | 5 | ||||
-rw-r--r-- | modules/ldap_oper.cpp | 13 | ||||
-rw-r--r-- | modules/memoserv/memoserv.cpp | 24 | ||||
-rw-r--r-- | modules/nickserv/nickserv.cpp | 7 | ||||
-rw-r--r-- | modules/nickserv/ns_register.cpp | 18 | ||||
-rw-r--r-- | modules/nickserv/ns_resetpass.cpp | 23 | ||||
-rw-r--r-- | modules/nickserv/ns_set.cpp | 24 | ||||
-rw-r--r-- | modules/operserv/os_defcon.cpp | 4 | ||||
-rw-r--r-- | modules/operserv/os_session.cpp | 4 | ||||
-rw-r--r-- | modules/proxyscan.cpp | 10 |
14 files changed, 102 insertions, 80 deletions
diff --git a/modules/chanserv/cs_akick.cpp b/modules/chanserv/cs_akick.cpp index 5453aa5d2..e6672b965 100644 --- a/modules/chanserv/cs_akick.cpp +++ b/modules/chanserv/cs_akick.cpp @@ -567,8 +567,10 @@ public: if (reason.empty()) { reason = Language::Translate(u, Config->GetModule(this).Get<const Anope::string>("autokickreason").c_str()); - reason = reason.replace_all_cs("%n", u->nick) - .replace_all_cs("%c", c->name); + reason = Anope::Template(reason, { + { "channel", c->name }, + { "nick", u->nick }, + }); } if (reason.empty()) reason = Language::Translate(u, _("User has been banned from the channel")); diff --git a/modules/chanserv/cs_ban.cpp b/modules/chanserv/cs_ban.cpp index 74dc129f4..8560e4eac 100644 --- a/modules/chanserv/cs_ban.cpp +++ b/modules/chanserv/cs_ban.cpp @@ -111,8 +111,7 @@ public: if (reason.length() > reasonmax) reason = reason.substr(0, reasonmax); - Anope::string signkickformat = Config->GetModule("chanserv").Get<Anope::string>("signkickformat", "%m (%n)"); - signkickformat = signkickformat.replace_all_cs("%n", source.GetNick()); + auto signkickformat = Config->GetModule("chanserv").Get<Anope::string>("signkickformat", "{message} ({nick})"); User *u = source.GetUser(); User *u2 = User::Find(target, true); @@ -160,7 +159,10 @@ public: { if (ci->HasExt("SIGNKICK") || (ci->HasExt("SIGNKICK_LEVEL") && !source.AccessFor(ci).HasPriv("SIGNKICK"))) { - signkickformat = signkickformat.replace_all_cs("%m", reason); + signkickformat = Anope::Template(signkickformat, { + { "message", reason }, + { "nick", source.GetNick() }, + }); c->Kick(ci->WhoSends(), u2, signkickformat); } else @@ -215,7 +217,10 @@ public: if (ci->HasExt("SIGNKICK") || (ci->HasExt("SIGNKICK_LEVEL") && !u_access.HasPriv("SIGNKICK"))) { reason += " (Matches " + mask + ")"; - signkickformat = signkickformat.replace_all_cs("%m", reason); + signkickformat = Anope::Template(signkickformat, { + { "message", reason }, + { "nick", source.GetNick() }, + }); c->Kick(ci->WhoSends(), uc->user, signkickformat); } else diff --git a/modules/chanserv/cs_kick.cpp b/modules/chanserv/cs_kick.cpp index 210a5168c..5ba61eaef 100644 --- a/modules/chanserv/cs_kick.cpp +++ b/modules/chanserv/cs_kick.cpp @@ -48,8 +48,7 @@ public: if (reason.length() > reasonmax) reason = reason.substr(0, reasonmax); - Anope::string signkickformat = Config->GetModule("chanserv").Get<Anope::string>("signkickformat", "%m (%n)"); - signkickformat = signkickformat.replace_all_cs("%n", source.GetNick()); + auto signkickformat = Config->GetModule("chanserv").Get<Anope::string>("signkickformat", "{message} ({nick})"); AccessGroup u_access = source.AccessFor(ci); @@ -71,7 +70,10 @@ public: if (ci->HasExt("SIGNKICK") || (ci->HasExt("SIGNKICK_LEVEL") && !u_access.HasPriv("SIGNKICK"))) { - signkickformat = signkickformat.replace_all_cs("%m", reason); + signkickformat = Anope::Template(signkickformat, { + { "message", reason }, + { "nick", source.GetNick() }, + }); c->Kick(ci->WhoSends(), u2, signkickformat); } else @@ -105,7 +107,10 @@ public: if (ci->HasExt("SIGNKICK") || (ci->HasExt("SIGNKICK_LEVEL") && !u_access.HasPriv("SIGNKICK"))) { reason += " (Matches " + mask + ")"; - signkickformat = signkickformat.replace_all_cs("%m", reason); + signkickformat = Anope::Template(signkickformat, { + { "message", reason }, + { "nick", source.GetNick() }, + }); c->Kick(ci->WhoSends(), uc->user, signkickformat); } else diff --git a/modules/dnsbl.cpp b/modules/dnsbl.cpp index 6db41ba84..e2e49e410 100644 --- a/modules/dnsbl.cpp +++ b/modules/dnsbl.cpp @@ -70,14 +70,16 @@ public: if (reply && reply->allow_account && user->IsIdentified()) return; - Anope::string reason = this->blacklist.reason, addr = user->ip.addr(); - reason = reason.replace_all_cs("%n", user->nick); - reason = reason.replace_all_cs("%u", user->GetIdent()); - reason = reason.replace_all_cs("%g", user->realname); - reason = reason.replace_all_cs("%h", user->host); - reason = reason.replace_all_cs("%i", addr); - reason = reason.replace_all_cs("%r", reply ? reply->reason : ""); - reason = reason.replace_all_cs("%N", Config->GetBlock("networkinfo").Get<const Anope::string>("networkname")); + auto addr = user->ip.addr(); + auto reason = Anope::Template(this->blacklist.reason, { + { "nick", user->nick }, + { "user", user->GetIdent() }, + { "real", user->realname }, + { "host", user->host }, + { "ip", addr }, + { "reply", reply ? reply->reason : "" }, + { "network", Config->GetBlock("networkinfo").Get<const Anope::string>("networkname") }, + }); BotInfo *OperServ = Config->GetClient("OperServ"); Log(creator, "dnsbl", OperServ) << user->GetMask() << " (" << addr << ") appears in " << this->blacklist.name; diff --git a/modules/ldap_authentication.cpp b/modules/ldap_authentication.cpp index f4e3ddd0a..5ca00bdf9 100644 --- a/modules/ldap_authentication.cpp +++ b/modules/ldap_authentication.cpp @@ -85,7 +85,10 @@ public: { if (ii->admin_bind) { - Anope::string sf = search_filter.replace_all_cs("%account", ii->req->GetAccount()).replace_all_cs("%object_class", object_class); + auto sf = Anope::Template(search_filter, { + { "account", ii->req->GetAccount() }, + { "object_class", object_class }, + }); try { Log(LOG_DEBUG) << "ldap_authentication: searching for " << sf; diff --git a/modules/ldap_oper.cpp b/modules/ldap_oper.cpp index fa57f7aa9..4d62052cd 100644 --- a/modules/ldap_oper.cpp +++ b/modules/ldap_oper.cpp @@ -117,8 +117,17 @@ public: throw LDAPException("Could not search LDAP for opertype settings, invalid configuration."); if (!this->binddn.empty()) - this->ldap->Bind(NULL, this->binddn.replace_all_cs("%a", u->Account()->display), this->password.c_str()); - this->ldap->Search(new IdentifyInterface(this, u), this->basedn, this->filter.replace_all_cs("%a", u->Account()->display)); + { + auto bdn = Anope::Template(this->binddn, { + { "account", u->Account()->display }, + }); + this->ldap->Bind(NULL, bdn, this->password.c_str()); + } + + auto af = Anope::Template(this->filter, { + { "account", u->Account()->display }, + }); + this->ldap->Search(new IdentifyInterface(this, u), this->basedn, af); } catch (const LDAPException &ex) { diff --git a/modules/memoserv/memoserv.cpp b/modules/memoserv/memoserv.cpp index a95a1fd87..b653e8ade 100644 --- a/modules/memoserv/memoserv.cpp +++ b/modules/memoserv/memoserv.cpp @@ -19,20 +19,16 @@ class MemoServCore final static bool SendMemoMail(NickCore *nc, MemoInfo *mi, Memo *m) { - Anope::string subject = Language::Translate(nc, Config->GetBlock("mail").Get<const Anope::string>("memo_subject").c_str()), - message = Language::Translate(nc, Config->GetBlock("mail").Get<const Anope::string>("memo_message").c_str()); - - subject = subject.replace_all_cs("%n", nc->display); - subject = subject.replace_all_cs("%s", m->sender); - subject = subject.replace_all_cs("%d", Anope::ToString(mi->GetIndex(m) + 1)); - subject = subject.replace_all_cs("%t", m->text); - subject = subject.replace_all_cs("%N", Config->GetBlock("networkinfo").Get<const Anope::string>("networkname")); - - message = message.replace_all_cs("%n", nc->display); - message = message.replace_all_cs("%s", m->sender); - message = message.replace_all_cs("%d", Anope::ToString(mi->GetIndex(m) + 1)); - message = message.replace_all_cs("%t", m->text); - message = message.replace_all_cs("%N", Config->GetBlock("networkinfo").Get<const Anope::string>("networkname")); + Anope::map<Anope::string> vars = { + { "receiver", nc->display }, + { "sender", m->sender }, + { "number", Anope::ToString(mi->GetIndex(m) + 1) }, + { "text", m->text }, + { "network", Config->GetBlock("networkinfo").Get<const Anope::string>("networkname") }, + }; + + auto subject = Anope::Template(Language::Translate(nc, Config->GetBlock("mail").Get<const Anope::string>("memo_subject").c_str()), vars); + auto message = Anope::Template(Language::Translate(nc, Config->GetBlock("mail").Get<const Anope::string>("memo_message").c_str()), vars); return Mail::Send(nc, subject, message); } diff --git a/modules/nickserv/nickserv.cpp b/modules/nickserv/nickserv.cpp index 80ffaf3cc..3358dcbef 100644 --- a/modules/nickserv/nickserv.cpp +++ b/modules/nickserv/nickserv.cpp @@ -432,7 +432,12 @@ public: const Anope::string &unregistered_notice = Config->GetModule(this).Get<const Anope::string>("unregistered_notice"); if (!Config->GetModule("nickserv").Get<bool>("nonicknameownership") && !unregistered_notice.empty() && !na && !u->IsIdentified()) - u->SendMessage(NickServ, unregistered_notice.replace_all_cs("%n", u->nick)); + { + auto msg = Anope::Template(unregistered_notice, { + { "nick", u->nick }, + }); + u->SendMessage(NickServ, msg); + } else if (na && !u->IsIdentified(true)) this->Validate(u); } diff --git a/modules/nickserv/ns_register.cpp b/modules/nickserv/ns_register.cpp index 1f049e851..2bcb8eac1 100644 --- a/modules/nickserv/ns_register.cpp +++ b/modules/nickserv/ns_register.cpp @@ -428,16 +428,14 @@ static bool SendRegmail(User *u, const NickAlias *na, BotInfo *bi) *code = Anope::Random(Config->GetBlock("options").Get<size_t>("codelength", 15)); } - Anope::string subject = Language::Translate(na->nc, Config->GetBlock("mail").Get<const Anope::string>("registration_subject").c_str()), - message = Language::Translate(na->nc, Config->GetBlock("mail").Get<const Anope::string>("registration_message").c_str()); - - subject = subject.replace_all_cs("%n", na->nick); - subject = subject.replace_all_cs("%N", Config->GetBlock("networkinfo").Get<const Anope::string>("networkname")); - subject = subject.replace_all_cs("%c", *code); - - message = message.replace_all_cs("%n", na->nick); - message = message.replace_all_cs("%N", Config->GetBlock("networkinfo").Get<const Anope::string>("networkname")); - message = message.replace_all_cs("%c", *code); + Anope::map<Anope::string> vars = { + { "nick", na->nick }, + { "network", Config->GetBlock("networkinfo").Get<const Anope::string>("networkname") }, + { "code", *code }, + }; + + auto subject = Anope::Template(Language::Translate(na->nc, Config->GetBlock("mail").Get<const Anope::string>("registration_subject").c_str()), vars); + auto message = Anope::Template(Language::Translate(na->nc, Config->GetBlock("mail").Get<const Anope::string>("registration_message").c_str()), vars); return Mail::Send(u, nc, bi, subject, message); } diff --git a/modules/nickserv/ns_resetpass.cpp b/modules/nickserv/ns_resetpass.cpp index 3eeae5052..7425ade66 100644 --- a/modules/nickserv/ns_resetpass.cpp +++ b/modules/nickserv/ns_resetpass.cpp @@ -132,21 +132,18 @@ public: static bool SendResetEmail(User *u, const NickAlias *na, BotInfo *bi) { - Anope::string subject = Language::Translate(na->nc, Config->GetBlock("mail").Get<const Anope::string>("reset_subject").c_str()), - message = Language::Translate(na->nc, Config->GetBlock("mail").Get<const Anope::string>("reset_message").c_str()), - passcode = Anope::Random(Config->GetBlock("options").Get<size_t>("codelength", 15)); - - subject = subject.replace_all_cs("%n", na->nick); - subject = subject.replace_all_cs("%N", Config->GetBlock("networkinfo").Get<const Anope::string>("networkname")); - subject = subject.replace_all_cs("%c", passcode); + auto *ri = na->nc->Extend<ResetInfo>("reset"); + ri->code = Anope::Random(Config->GetBlock("options").Get<size_t>("codelength", 15)); + ri->time = Anope::CurTime; - message = message.replace_all_cs("%n", na->nick); - message = message.replace_all_cs("%N", Config->GetBlock("networkinfo").Get<const Anope::string>("networkname")); - message = message.replace_all_cs("%c", passcode); + Anope::map<Anope::string> vars = { + { "nick", na->nick }, + { "network", Config->GetBlock("networkinfo").Get<const Anope::string>("networkname") }, + { "code", ri->code }, + }; - ResetInfo *ri = na->nc->Extend<ResetInfo>("reset"); - ri->code = passcode; - ri->time = Anope::CurTime; + auto subject = Anope::Template(Language::Translate(na->nc, Config->GetBlock("mail").Get<const Anope::string>("reset_subject").c_str()), vars); + auto message = Anope::Template(Language::Translate(na->nc, Config->GetBlock("mail").Get<const Anope::string>("reset_message").c_str()), vars); return Mail::Send(u, na->nc, bi, subject, message); } diff --git a/modules/nickserv/ns_set.cpp b/modules/nickserv/ns_set.cpp index 39da08053..b8f6c257b 100644 --- a/modules/nickserv/ns_set.cpp +++ b/modules/nickserv/ns_set.cpp @@ -528,20 +528,16 @@ class CommandNSSetEmail n->first = new_email; n->second = code; - Anope::string subject = Config->GetBlock("mail").Get<const Anope::string>("emailchange_subject"), - message = Config->GetBlock("mail").Get<const Anope::string>("emailchange_message"); - - subject = subject.replace_all_cs("%e", nc->email); - subject = subject.replace_all_cs("%E", new_email); - subject = subject.replace_all_cs("%n", nc->display); - subject = subject.replace_all_cs("%N", Config->GetBlock("networkinfo").Get<const Anope::string>("networkname")); - subject = subject.replace_all_cs("%c", code); - - message = message.replace_all_cs("%e", nc->email); - message = message.replace_all_cs("%E", new_email); - message = message.replace_all_cs("%n", nc->display); - message = message.replace_all_cs("%N", Config->GetBlock("networkinfo").Get<const Anope::string>("networkname")); - message = message.replace_all_cs("%c", code); + Anope::map<Anope::string> vars = { + { "old_email", nc->email }, + { "new_email", new_email }, + { "account", nc->display }, + { "network", Config->GetBlock("networkinfo").Get<const Anope::string>("networkname") }, + { "code", code }, + }; + + auto subject = Anope::Template(Config->GetBlock("mail").Get<const Anope::string>("emailchange_subject"), vars); + auto message = Anope::Template(Config->GetBlock("mail").Get<const Anope::string>("emailchange_message"), vars); Anope::string old = nc->email; nc->email = new_email; diff --git a/modules/operserv/os_defcon.cpp b/modules/operserv/os_defcon.cpp index 49ba77b0a..53ceef8a3 100644 --- a/modules/operserv/os_defcon.cpp +++ b/modules/operserv/os_defcon.cpp @@ -513,7 +513,9 @@ public: { if (!DConfig.sle_reason.empty()) { - Anope::string message = DConfig.sle_reason.replace_all_cs("%IP%", u->ip.addr()); + auto message = Anope::Template(DConfig.sle_reason, { + { "ip", u->ip.addr() }, + }); u->SendMessage(OperServ, message); } if (!DConfig.sle_detailsloc.empty()) diff --git a/modules/operserv/os_session.cpp b/modules/operserv/os_session.cpp index 3db90f132..858b1b2a9 100644 --- a/modules/operserv/os_session.cpp +++ b/modules/operserv/os_session.cpp @@ -696,7 +696,9 @@ public: { if (!sle_reason.empty()) { - Anope::string message = sle_reason.replace_all_cs("%IP%", u->ip.addr()); + auto message = Anope::Template(sle_reason, { + { "ip", u->ip.addr() }, + }); u->SendMessage(OperServ, message); } if (!sle_detailsloc.empty()) diff --git a/modules/proxyscan.cpp b/modules/proxyscan.cpp index 8b814ec0a..4984034d7 100644 --- a/modules/proxyscan.cpp +++ b/modules/proxyscan.cpp @@ -84,11 +84,11 @@ public: protected: void Ban() { - Anope::string reason = this->proxy.reason; - - reason = reason.replace_all_cs("%t", this->GetType()); - reason = reason.replace_all_cs("%i", this->conaddr.addr()); - reason = reason.replace_all_cs("%p", Anope::ToString(this->conaddr.port())); + auto reason = Anope::Template(this->proxy.reason, { + { "ip", this->conaddr.addr() }, + { "port", Anope::ToString(this->conaddr.port()) }, + { "type", this->GetType() }, + }); BotInfo *OperServ = Config->GetClient("OperServ"); Log(OperServ) << "PROXYSCAN: Open " << this->GetType() << " proxy found on " << this->conaddr.str() << " (" << reason << ")"; |