Anope IRC Services  Version 2.0
ms_send.cpp
Go to the documentation of this file.
1 /* MemoServ 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 namespace
15 {
16  ServiceReference<MemoServService> memoserv("MemoServService", "MemoServ");
17 }
18 
19 class CommandMSSend : public Command
20 {
21  public:
22  CommandMSSend(Module *creator) : Command(creator, "memoserv/send", 2, 2)
23  {
24  this->SetDesc(_("Send a memo to a nick or channel"));
25  this->SetSyntax(_("{\037nick\037 | \037channel\037} \037memo-text\037"));
26  }
27 
28  void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
29  {
30  if (!memoserv)
31  return;
32 
33  const Anope::string &nick = params[0];
34  const Anope::string &text = params[1];
35 
36  if (Anope::ReadOnly && !source.IsOper())
37  {
38  source.Reply(MEMO_SEND_DISABLED);
39  return;
40  }
41 
42  MemoServService::MemoResult result = memoserv->Send(source.GetNick(), nick, text);
43  if (result == MemoServService::MEMO_SUCCESS)
44  source.Reply(_("Memo sent to \002%s\002."), nick.c_str());
45  else if (result == MemoServService::MEMO_INVALID_TARGET)
46  source.Reply(_("\002%s\002 is not a registered unforbidden nick or channel."), nick.c_str());
47  else if (result == MemoServService::MEMO_TOO_FAST)
48  source.Reply(_("Please wait %d seconds before using the %s command again."), Config->GetModule("memoserv")->Get<time_t>("senddelay"), source.command.c_str());
49  else if (result == MemoServService::MEMO_TARGET_FULL)
50  source.Reply(_("Sorry, %s currently has too many memos and cannot receive more."), nick.c_str());
51  }
52 
53  bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
54  {
55  this->SendSyntax(source);
56  source.Reply(" ");
57  source.Reply(_("Sends the named \037nick\037 or \037channel\037 a memo containing\n"
58  "\037memo-text\037. When sending to a nickname, the recipient will\n"
59  "receive a notice that he/she has a new memo. The target\n"
60  "nickname/channel must be registered."));
61  return true;
62  }
63 };
64 
65 class MSSend : public Module
66 {
68 
69  public:
70  MSSend(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
71  commandmssend(this)
72  {
73 
74  if (!memoserv)
75  throw ModuleException("No MemoServ!");
76  }
77 };
78 
CoreExport bool ReadOnly
Definition: main.cpp:28
void Execute(CommandSource &source, const std::vector< Anope::string > &params) anope_override
Definition: ms_send.cpp:28
bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
Definition: ms_send.cpp:53
CommandMSSend(Module *creator)
Definition: ms_send.cpp:22
void SetDesc(const Anope::string &d)
Definition: command.cpp:130
Definition: Config.cs:26
#define MEMO_SEND_DISABLED
Definition: language.h:117
static ServiceReference< MemoServService > memoserv("MemoServService","MemoServ")
#define anope_override
Definition: services.h:56
MSSend(const Anope::string &modname, const Anope::string &creator)
Definition: ms_send.cpp:70
#define MODULE_INIT(x)
Definition: modules.h:45
CommandMSSend commandmssend
Definition: ms_send.cpp:67
void SetSyntax(const Anope::string &s)
Definition: command.cpp:140
void SendSyntax(CommandSource &)
Definition: command.cpp:145
const char * c_str() const
Definition: anope.h:117
#define _(x)
Definition: services.h:50