Anope IRC Services  Version 2.0
cs_invite.cpp
Go to the documentation of this file.
1 /* ChanServ core functions
2  *
3  * (C) 2003-2014 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 and above\n"
95  "on the channel."), source.service->nick.c_str());
96  return true;
97  }
98 };
99 
100 class CSInvite : public Module
101 {
103 
104  public:
105  CSInvite(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), commandcsinvite(this)
106  {
107 
108  }
109 };
110 
CSInvite(const Anope::string &modname, const Anope::string &creator)
Definition: cs_invite.cpp:105
bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
Definition: cs_invite.cpp:87
CommandCSInvite commandcsinvite
Definition: cs_invite.cpp:102
Definition: hashcomp.h:84
virtual void SendInvite(const MessageSource &source, const Channel *c, User *u)
Definition: protocol.cpp:284
#define CHAN_X_NOT_IN_USE
Definition: language.h:85
#define ACCESS_DENIED
Definition: language.h:73
Definition: users.h:34
void SetDesc(const Anope::string &d)
Definition: command.cpp:130
Serialize::Reference< ChannelInfo > ci
Definition: channels.h:46
Anope::string name
Definition: channels.h:44
#define NICK_X_NOT_IN_USE
Definition: language.h:80
BotInfo * WhoSends() const
Definition: regchannel.cpp:383
#define anope_override
Definition: services.h:56
CoreExport IRCDProto * IRCD
Definition: protocol.cpp:23
#define MODULE_INIT(x)
Definition: modules.h:45
ChanUserContainer * FindUser(User *u) const
Definition: channels.cpp:173
void SetSyntax(const Anope::string &s)
Definition: command.cpp:140
#define CHAN_X_NOT_REGISTERED
Definition: language.h:84
Anope::string nick
Definition: users.h:62
static User * Find(const Anope::string &name, bool nick_only=false)
Definition: users.cpp:815
static Channel * Find(const Anope::string &name)
Definition: channels.cpp:920
CommandCSInvite(Module *creator)
Definition: cs_invite.cpp:17
void SendSyntax(CommandSource &)
Definition: command.cpp:145
const char * c_str() const
Definition: anope.h:117
Definition: logger.h:53
void SendMessage(BotInfo *source, const char *fmt,...)
Definition: users.cpp:320
#define _(x)
Definition: services.h:50
void Execute(CommandSource &source, const std::vector< Anope::string > &params) anope_override
Definition: cs_invite.cpp:23