summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2013-02-24 20:11:16 -0500
committerAdam <Adam@anope.org>2013-02-24 20:15:49 -0500
commit5d4db2b85408202086ae35f38306e81f9216959e (patch)
treedf071c149dd1b0be6a76dee5d76fcb62db363190
parent501503b7a5b80343c78354e3e4045528198edf80 (diff)
Allow /cs up and /cs down to take an optional nick arg
-rw-r--r--modules/commands/cs_updown.cpp100
1 files changed, 75 insertions, 25 deletions
diff --git a/modules/commands/cs_updown.cpp b/modules/commands/cs_updown.cpp
index 6c384af43..85eeb0af1 100644
--- a/modules/commands/cs_updown.cpp
+++ b/modules/commands/cs_updown.cpp
@@ -16,34 +16,58 @@
class CommandCSUp : public Command
{
public:
- CommandCSUp(Module *creator) : Command(creator, "chanserv/up", 0, 3)
+ CommandCSUp(Module *creator) : Command(creator, "chanserv/up", 0, 2)
{
- this->SetDesc(_("Updates your status on a channel"));
- this->SetSyntax(_("[\037channel\037]"));
- this->RequireUser(true);
+ this->SetDesc(_("Updates a selected nicks status on a channel"));
+ this->SetSyntax(_("[\037channel\037 [\037nick\037]]"));
}
void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
{
- User *u = source.GetUser();
-
if (params.empty())
- for (User::ChanUserList::iterator it = u->chans.begin(); it != u->chans.end(); ++it)
+ {
+ if (!source.GetUser())
+ return;
+ for (User::ChanUserList::iterator it = source.GetUser()->chans.begin(); it != source.GetUser()->chans.end(); ++it)
{
Channel *c = (*it)->chan;
- c->SetCorrectModes(u, true, false);
+ c->SetCorrectModes(source.GetUser(), true, false);
}
+ }
else
{
const Anope::string &channel = params[0];
- Channel *c = Channel::Find(params[0]);
-
+ const Anope::string &nick = params.size() > 1 ? params[1] : source.GetNick();
+
+ Channel *c = Channel::Find(channel);
+
if (c == NULL)
+ {
source.Reply(CHAN_X_NOT_IN_USE, channel.c_str());
+ return;
+ }
else if (!c->ci)
+ {
source.Reply(CHAN_X_NOT_REGISTERED, channel.c_str());
- else
- c->SetCorrectModes(u, true, false);
+ return;
+ }
+
+ User *u = User::Find(nick, true);
+ if (u == NULL)
+ {
+ source.Reply(NICK_X_NOT_IN_USE, nick.c_str());
+ return;
+ }
+ else if (source.GetUser() && u != source.GetUser() && c->ci->HasExt("PEACE"))
+ {
+ if (c->ci->AccessFor(u) > c->ci->AccessFor(source.GetUser()))
+ {
+ source.Reply(ACCESS_DENIED);
+ return;
+ }
+ }
+
+ c->SetCorrectModes(u, true, false);
}
}
@@ -52,7 +76,8 @@ class CommandCSUp : public Command
{
this->SendSyntax(source);
source.Reply(" ");
- source.Reply(_("Updates your status modes on a channel. If \037channel\037 is ommited\n"
+ source.Reply(_("Updates a selected nicks status modes on a channel. If \037nick\037 is\n"
+ "ommited then your status is updated. If \037channel\037 is ommited then\n"
"your channel status is updated on every channel you are in."));
return true;
}
@@ -72,34 +97,58 @@ class CommandCSDown : public Command
}
public:
- CommandCSDown(Module *creator) : Command(creator, "chanserv/down", 0, 3)
+ CommandCSDown(Module *creator) : Command(creator, "chanserv/down", 0, 2)
{
- this->SetDesc(_("Removes your status from a channel"));
- this->SetSyntax(_("[\037channel\037]"));
- this->RequireUser(true);
+ this->SetDesc(_("Removes a selected nicks status from a channel"));
+ this->SetSyntax(_("[\037channel\037 ]\037nick\037]]"));
}
void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
{
- User *u = source.GetUser();
-
if (params.empty())
- for (User::ChanUserList::iterator it = u->chans.begin(); it != u->chans.end(); ++it)
+ {
+ if (!source.GetUser())
+ return;
+ for (User::ChanUserList::iterator it = source.GetUser()->chans.begin(); it != source.GetUser()->chans.end(); ++it)
{
Channel *c = (*it)->chan;
- RemoveAll(u, c);
+ RemoveAll(source.GetUser(), c);
}
+ }
else
{
const Anope::string &channel = params[0];
- Channel *c = Channel::Find(params[0]);
+ const Anope::string &nick = params.size() > 1 ? params[1] : source.GetNick();
+
+ Channel *c = Channel::Find(channel);
if (c == NULL)
+ {
source.Reply(CHAN_X_NOT_IN_USE, channel.c_str());
+ return;
+ }
else if (!c->ci)
+ {
source.Reply(CHAN_X_NOT_REGISTERED, channel.c_str());
- else
- RemoveAll(u, c);
+ return;
+ }
+
+ User *u = User::Find(nick, true);
+ if (u == NULL)
+ {
+ source.Reply(NICK_X_NOT_IN_USE, nick.c_str());
+ return;
+ }
+ else if (source.GetUser() && u != source.GetUser() && c->ci->HasExt("PEACE"))
+ {
+ if (c->ci->AccessFor(u) > c->ci->AccessFor(source.GetUser()))
+ {
+ source.Reply(ACCESS_DENIED);
+ return;
+ }
+ }
+
+ RemoveAll(u, c);
}
}
@@ -107,7 +156,8 @@ class CommandCSDown : public Command
{
this->SendSyntax(source);
source.Reply(" ");
- source.Reply(_("Removes your status modes on a channel. If \037channel\037 is ommited\n"
+ source.Reply(_("Removes a selected nicks status modes on a channel. If \037nick\037 is\n"
+ "ommited then your status is removed. If \037channel\037 is ommited then\n"
"your channel status is removed on every channel you are in."));
return true;
}