anope

- supernets anope source code & configuration
git clone git://git.acid.vegas/anope.git
Log | Files | Refs | Archive | README

cs_invite.cpp (2846B)

      1 /* ChanServ core functions
      2  *
      3  * (C) 2003-2022 Anope Team
      4  * Contact us at team@anope.org
      5  *
      6  * Please read COPYING and README for further details.
      7  *
      8  * Based on the original code of Epona by Lara.
      9  * Based on the original code of Services by Andy Church.
     10  */
     11 
     12 #include "module.h"
     13 
     14 class CommandCSInvite : public Command
     15 {
     16  public:
     17 	CommandCSInvite(Module *creator) : Command(creator, "chanserv/invite", 1, 3)
     18 	{
     19 		this->SetDesc(_("Invites you or an optionally specified nick into a channel"));
     20 		this->SetSyntax(_("\037channel\037 [\037nick\037]"));
     21 	}
     22 
     23 	void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
     24 	{
     25 		const Anope::string &chan = params[0];
     26 
     27 		User *u = source.GetUser();
     28 		Channel *c = Channel::Find(chan);
     29 
     30 		if (!c)
     31 		{
     32 			source.Reply(CHAN_X_NOT_IN_USE, chan.c_str());
     33 			return;
     34 		}
     35 
     36 		ChannelInfo *ci = c->ci;
     37 		if (!ci)
     38 		{
     39 			source.Reply(CHAN_X_NOT_REGISTERED, chan.c_str());
     40 			return;
     41 		}
     42 
     43 		if (!source.AccessFor(ci).HasPriv("INVITE") && !source.HasCommand("chanserv/invite"))
     44 		{
     45 			source.Reply(ACCESS_DENIED);
     46 			return;
     47 		}
     48 
     49 		User *u2;
     50 		if (params.size() == 1)
     51 			u2 = u;
     52 		else
     53 			u2 = User::Find(params[1], true);
     54 
     55 		if (!u2)
     56 		{
     57 			source.Reply(NICK_X_NOT_IN_USE, params.size() > 1 ? params[1].c_str() : source.GetNick().c_str());
     58 			return;
     59 		}
     60 
     61 		if (c->FindUser(u2))
     62 		{
     63 			if (u2 == u)
     64 				source.Reply(_("You are already in \002%s\002!"), c->name.c_str());
     65 			else
     66 				source.Reply(_("\002%s\002 is already in \002%s\002!"), u2->nick.c_str(), c->name.c_str());
     67 		}
     68 		else
     69 		{
     70 			bool override = !source.AccessFor(ci).HasPriv("INVITE");
     71 
     72 			IRCD->SendInvite(ci->WhoSends(), c, u2);
     73 			if (u2 != u)
     74 			{
     75 				source.Reply(_("\002%s\002 has been invited to \002%s\002."), u2->nick.c_str(), c->name.c_str());
     76 				u2->SendMessage(ci->WhoSends(), _("You have been invited to \002%s\002 by \002%s\002."), c->name.c_str(), source.GetNick().c_str());
     77 				Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "for " << u2->nick;
     78 			}
     79 			else
     80 			{
     81 				u2->SendMessage(ci->WhoSends(), _("You have been invited to \002%s\002."), c->name.c_str());
     82 				Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci);
     83 			}
     84 		}
     85 	}
     86 
     87 	bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
     88 	{
     89 		this->SendSyntax(source);
     90 		source.Reply(" ");
     91 		source.Reply(_("Tells %s to invite you or an optionally specified\n"
     92 				"nick into the given channel.\n"
     93 				" \n"
     94 				"By default, limited to AOPs or those with level 5 access and above\n"
     95 				"on the channel."), source.service->nick.c_str());
     96 		return true;
     97 	}
     98 };
     99 
    100 class CSInvite : public Module
    101 {
    102 	CommandCSInvite commandcsinvite;
    103 
    104  public:
    105 	CSInvite(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), commandcsinvite(this)
    106 	{
    107 
    108 	}
    109 };
    110 
    111 MODULE_INIT(CSInvite)