diff --git a/language/anope.en_US.po b/language/anope.en_US.po index f1ea7c0a7..69507a6a9 100644 --- a/language/anope.en_US.po +++ b/language/anope.en_US.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: Anope\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2025-11-10 02:45+0000\n" +"POT-Creation-Date: 2025-11-11 21:08+0000\n" "PO-Revision-Date: 2025-11-10 02:45+0000\n" "Last-Translator: Sadie Powell \n" "Language-Team: English\n" @@ -762,11 +762,11 @@ msgid "%c is an unknown status mode." msgstr "" #, c-format -msgid "%c%c is not locked on %s." +msgid "%c%c can not be locked on %s." msgstr "" #, c-format -msgid "%c%c%s has been unlocked from %s." +msgid "%c%c is not locked on %s." msgstr "" #, c-format @@ -987,6 +987,14 @@ msgstr "" msgid "%s had an invalid key specified, and was thus ignored." msgstr "" +#, c-format +msgid "%s has been locked on %s." +msgstr "" + +#, c-format +msgid "%s has been unlocked from %s." +msgstr "" + #, c-format msgid "%s has no memo limit." msgstr "" @@ -1080,10 +1088,6 @@ msgstr "" msgid "%s list is empty." msgstr "" -#, c-format -msgid "%s locked on %s." -msgstr "" - #, c-format msgid "%s not found." msgstr "" diff --git a/modules/chanserv/cs_mode.cpp b/modules/chanserv/cs_mode.cpp index 5af811bf8..3b06a4ca1 100644 --- a/modules/chanserv/cs_mode.cpp +++ b/modules/chanserv/cs_mode.cpp @@ -12,6 +12,43 @@ #include "module.h" #include "modules/chanserv/mode.h" +class ModeFormatter final +{ +private: + Anope::string addmodes; + Anope::string addparams; + Anope::string delmodes; + Anope::string delparams; + +public: + void Push(ChannelMode* cm, const Anope::string ¶m, bool adding) + { + if (adding) + { + this->addmodes.push_back(cm->mchar); + if (!param.empty()) + this->addparams.append(" ").append(param); + } + else + { + this->delmodes.push_back(cm->mchar); + if (!param.empty()) + this->delparams.append(" ").append(param); + + } + } + + Anope::string ToString() const + { + Anope::string buffer; + if (!addmodes.empty()) + buffer.append("+").append(addmodes).append(addparams); + if (!delmodes.empty()) + buffer.append("-").append(delmodes).append(delparams); + return buffer; + } +}; + struct ModeLockImpl final : ModeLock , Serializable @@ -178,30 +215,14 @@ struct ModeLocksImpl final Anope::string GetMLockAsString(bool complete) const override { - Anope::string pos = "+", neg = "-", params; - + ModeFormatter formatter; for (auto *ml : *this->mlocks) { - ChannelMode *cm = ModeManager::FindChannelModeByName(ml->name); - - if (!cm || cm->type == MODE_LIST || cm->type == MODE_STATUS) - continue; - - if (ml->set) - pos += cm->mchar; - else - neg += cm->mchar; - - if (complete && ml->set && !ml->param.empty() && cm->type == MODE_PARAM) - params += " " + ml->param; + auto *cm = ModeManager::FindChannelModeByName(ml->name); + if (cm && cm->type != MODE_LIST && cm->type != MODE_STATUS) + formatter.Push(cm, ml->param, ml->set); } - - if (pos.length() == 1) - pos.clear(); - if (neg.length() == 1) - neg.clear(); - - return pos + neg + params; + return formatter.ToString(); } void Check() override @@ -298,9 +319,9 @@ class CommandCSMode final sep.GetToken(modes); - Anope::string pos = "+", neg = "-", pos_params, neg_params; + ModeFormatter formatter; - int adding = 1; + int adding = -1; bool needreply = true; for (auto mode : modes) { @@ -351,32 +372,17 @@ class CommandCSMode final continue; } - modelocks->SetMLock(cm, adding, mode_param, source.GetNick()); - - if (adding) - { - pos += cm->mchar; - if (!mode_param.empty()) - pos_params += " " + mode_param; - } + if (modelocks->SetMLock(cm, adding, mode_param, source.GetNick())) + formatter.Push(cm, mode_param, adding); else - { - neg += cm->mchar; - if (!mode_param.empty()) - neg_params += " " + mode_param; - } + source.Reply(_("%c%c can not be locked on %s."), adding == 1 ? '+' : '-', cm->mchar, ci->name.c_str()); } } - if (pos == "+") - pos.clear(); - if (neg == "-") - neg.clear(); - Anope::string reply = pos + neg + pos_params + neg_params; - + const auto reply = formatter.ToString(); if (!reply.empty()) { - source.Reply(_("%s locked on %s."), reply.c_str(), ci->name.c_str()); + source.Reply(_("%s has been locked on %s."), reply.c_str(), ci->name.c_str()); Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to lock " << reply; } else if (needreply) @@ -392,6 +398,8 @@ class CommandCSMode final sep.GetToken(modes); + ModeFormatter formatter; + int adding = 1; bool needreply = true; for (auto mode : modes) @@ -424,19 +432,20 @@ class CommandCSMode final else { if (modelocks->RemoveMLock(cm, adding, mode_param)) - { - if (!mode_param.empty()) - mode_param = " " + mode_param; - source.Reply(_("%c%c%s has been unlocked from %s."), adding == 1 ? '+' : '-', cm->mchar, mode_param.c_str(), ci->name.c_str()); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to unlock " << (adding ? '+' : '-') << cm->mchar << mode_param; - } + formatter.Push(cm, mode_param, adding); else source.Reply(_("%c%c is not locked on %s."), adding == 1 ? '+' : '-', cm->mchar, ci->name.c_str()); } } } - if (needreply) + const auto reply = formatter.ToString(); + if (!reply.empty()) + { + source.Reply(_("%s has been unlocked from %s."), reply.c_str(), ci->name.c_str()); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to lock " << reply; + } + else if (needreply) source.Reply(_("Nothing to do.")); } else if (subcommand.equals_ci("LIST"))