summaryrefslogtreecommitdiff
path: root/modules/nickserv
diff options
context:
space:
mode:
authorSadie Powell <sadie@witchery.services>2025-04-14 11:31:19 +0100
committerSadie Powell <sadie@witchery.services>2025-04-14 11:31:19 +0100
commitd04a312d0d1edd1223b55ed89b7fb707ceca3117 (patch)
tree39b0c165b17d5ff4571423b2bc279b34546c3b72 /modules/nickserv
parent099f0ce43a7e34e4a6e74d91aa911c745c262ba8 (diff)
Add Anope::Templace and switch all template strings to use it.
Diffstat (limited to 'modules/nickserv')
-rw-r--r--modules/nickserv/nickserv.cpp7
-rw-r--r--modules/nickserv/ns_register.cpp18
-rw-r--r--modules/nickserv/ns_resetpass.cpp23
-rw-r--r--modules/nickserv/ns_set.cpp24
4 files changed, 34 insertions, 38 deletions
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;