1
0
mirror of https://github.com/anope/anope.git synced 2026-06-12 19:14:47 +02:00

Centralise logic for determining if a mode needs a param in cs_mode.

This commit is contained in:
Sadie Powell
2025-11-12 21:33:59 +00:00
parent 989a2da73a
commit 0fffae7bb5
+19 -2
View File
@@ -288,6 +288,23 @@ class CommandCSMode final
return source.AccessFor(ci).HasPriv(cm->name + (self ? "ME" : ""));
}
static bool NeedsParam(ChannelMode *cm, bool adding)
{
switch (cm->type)
{
case MODE_REGULAR:
return false;
case MODE_LIST:
case MODE_STATUS:
return true;
case MODE_PARAM:
return !anope_dynamic_static_cast<ChannelModeParam *>(cm)->minus_no_arg;
}
return false;
}
void DoLock(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> &params)
{
User *u = source.GetUser();
@@ -351,7 +368,7 @@ class CommandCSMode final
}
Anope::string mode_param;
if (((cm->type == MODE_STATUS || cm->type == MODE_LIST) && !sep.GetToken(mode_param)) || (cm->type == MODE_PARAM && adding && !sep.GetToken(mode_param)))
if (NeedsParam(cm, adding) && !sep.GetToken(mode_param))
{
source.Reply(_("Missing parameter for mode %c."), cm->mchar);
continue;
@@ -430,7 +447,7 @@ class CommandCSMode final
}
Anope::string mode_param;
if ((cm->type == MODE_LIST || cm->type == MODE_STATUS) && !sep.GetToken(mode_param))
if (NeedsParam(cm, adding) && !sep.GetToken(mode_param))
source.Reply(_("Missing parameter for mode %c."), cm->mchar);
else
{