From 852aae5e4f243d5bc8abfd0f52dfe4e2ccf45fd6 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Sat, 13 Dec 2025 20:18:47 +0000 Subject: [PATCH] Fix the syntax of chanserv/suspend and nickserv/suspend. Closes #540 Closes #547 --- modules/chanserv/cs_suspend.cpp | 48 +++++++++++----------- modules/nickserv/ns_suspend.cpp | 70 ++++++++++++++++----------------- 2 files changed, 60 insertions(+), 58 deletions(-) diff --git a/modules/chanserv/cs_suspend.cpp b/modules/chanserv/cs_suspend.cpp index 303222e87..836a6bc0c 100644 --- a/modules/chanserv/cs_suspend.cpp +++ b/modules/chanserv/cs_suspend.cpp @@ -69,7 +69,8 @@ class CommandCSSuspend final : public Command { public: - CommandCSSuspend(Module *creator) : Command(creator, "chanserv/suspend", 2, 3) + CommandCSSuspend(Module *creator) + : Command(creator, "chanserv/suspend", 1, 3) { this->SetDesc(_("Prevent a channel from being used preserving channel data and settings")); this->SetSyntax(_("\037channel\037 [+\037expiry\037] [\037reason\037]")); @@ -77,31 +78,14 @@ public: void Execute(CommandSource &source, const std::vector ¶ms) override { - const Anope::string &chan = params[0]; - Anope::string expiry = params[1]; - Anope::string reason = params.size() > 2 ? params[2] : ""; - time_t expiry_secs = Config->GetModule(this->owner).Get("suspendexpire"); - - if (!expiry.empty() && expiry[0] != '+') - { - reason = expiry + " " + reason; - reason.trim(); - expiry.clear(); - } - else - { - expiry_secs = Anope::DoTime(expiry); - if (expiry_secs < 0) - { - source.Reply(BAD_EXPIRY_TIME); - return; - } - } - if (Anope::ReadOnly) + { source.Reply(READ_ONLY_MODE); + return; + } - ChannelInfo *ci = ChannelInfo::Find(chan); + const auto &chan = params[0]; + auto *ci = ChannelInfo::Find(chan); if (ci == NULL) { source.Reply(CHAN_X_NOT_REGISTERED, chan.c_str()); @@ -114,6 +98,24 @@ public: return; } + const size_t expiry_idx = params.size() >= 1 && params[1][0] == '+' ? 1 : 0; + const size_t reason_idx = expiry_idx ? 2 : 1; + + time_t expiry_secs = Config->GetModule(this->owner).Get("suspendexpire"); + if (expiry_idx != 0) + { + expiry_secs = Anope::DoTime(params[expiry_idx].substr(1)); + if (expiry_secs < 0) + { + source.Reply(BAD_EXPIRY_TIME); + return; + } + } + + Anope::string reason; + for (auto idx = reason_idx; idx < params.size(); ++idx) + reason.append(reason.empty() ? "" : " ").append(params[idx]); + CSSuspendInfo *si = ci->Extend("CS_SUSPENDED"); si->what = ci->name; si->by = source.GetNick(); diff --git a/modules/nickserv/ns_suspend.cpp b/modules/nickserv/ns_suspend.cpp index 990d4a7ba..4acfdf9a9 100644 --- a/modules/nickserv/ns_suspend.cpp +++ b/modules/nickserv/ns_suspend.cpp @@ -70,7 +70,8 @@ class CommandNSSuspend final : public Command { public: - CommandNSSuspend(Module *creator) : Command(creator, "nickserv/suspend", 2, 3) + CommandNSSuspend(Module *creator) + : Command(creator, "nickserv/suspend", 1, 3) { this->SetDesc(_("Suspend a given nick")); this->SetSyntax(_("\037nickname\037 [+\037expiry\037] [\037reason\037]")); @@ -78,24 +79,40 @@ public: void Execute(CommandSource &source, const std::vector ¶ms) override { - - const Anope::string &nick = params[0]; - Anope::string expiry = params[1]; - Anope::string reason = params.size() > 2 ? params[2] : ""; - time_t expiry_secs = Config->GetModule(this->owner).Get("suspendexpire"); - if (Anope::ReadOnly) + { source.Reply(READ_ONLY_MODE); - - if (expiry[0] != '+') - { - reason = expiry + " " + reason; - reason.trim(); - expiry.clear(); + return; } - else + + const auto &nick = params[0]; + auto *na = NickAlias::Find(nick); + if (!na) { - expiry_secs = Anope::DoTime(expiry); + source.Reply(NICK_X_NOT_REGISTERED, nick.c_str()); + return; + } + + NickCore *nc = na->nc; + if (Config->GetModule("nickserv").Get("secureadmins", "yes") && nc->IsServicesOper()) + { + source.Reply(_("You may not suspend other Services Operators' nicknames.")); + return; + } + + if (nc->HasExt("NS_SUSPENDED")) + { + source.Reply(_("\002%s\002 is already suspended."), na->nc->display.c_str()); + return; + } + + const size_t expiry_idx = params.size() >= 1 && params[1][0] == '+' ? 1 : 0; + const size_t reason_idx = expiry_idx ? 2 : 1; + + time_t expiry_secs = Config->GetModule(this->owner).Get("suspendexpire"); + if (expiry_idx != 0) + { + expiry_secs = Anope::DoTime(params[expiry_idx].substr(1)); if (expiry_secs < 0) { source.Reply(BAD_EXPIRY_TIME); @@ -103,26 +120,9 @@ public: } } - NickAlias *na = NickAlias::Find(nick); - if (!na) - { - source.Reply(NICK_X_NOT_REGISTERED, nick.c_str()); - return; - } - - if (Config->GetModule("nickserv").Get("secureadmins", "yes") && na->nc->IsServicesOper()) - { - source.Reply(_("You may not suspend other Services Operators' nicknames.")); - return; - } - - if (na->nc->HasExt("NS_SUSPENDED")) - { - source.Reply(_("\002%s\002 is already suspended."), na->nc->display.c_str()); - return; - } - - NickCore *nc = na->nc; + Anope::string reason; + for (auto idx = reason_idx; idx < params.size(); ++idx) + reason.append(reason.empty() ? "" : " ").append(params[idx]); NSSuspendInfo *si = nc->Extend("NS_SUSPENDED"); si->what = nc->display;