Anope IRC Services  Version 2.0
ms_rsend.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 CommandMSRSend : public Command
20 {
21  public:
22  CommandMSRSend(Module *creator) : Command(creator, "memoserv/rsend", 2, 2)
23  {
24  this->SetDesc(_("Sends a memo and requests a read receipt"));
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  if (Anope::ReadOnly && !source.IsOper())
34  {
35  source.Reply(MEMO_SEND_DISABLED);
36  return;
37  }
38 
39  const Anope::string &nick = params[0];
40  const Anope::string &text = params[1];
41  const NickAlias *na = NULL;
42 
43  /* prevent user from rsend to themselves */
44  if ((na = NickAlias::Find(nick)) && na->nc == source.GetAccount())
45  {
46  source.Reply(_("You can not request a receipt when sending a memo to yourself."));
47  return;
48  }
49 
50  if (Config->GetModule(this->owner)->Get<bool>("operonly") && !source.IsServicesOper())
51  source.Reply(ACCESS_DENIED);
52  else
53  {
54  MemoServService::MemoResult result = memoserv->Send(source.GetNick(), nick, text);
56  source.Reply(_("\002%s\002 is not a registered unforbidden nick or channel."), nick.c_str());
57  else if (result == MemoServService::MEMO_TOO_FAST)
58  source.Reply(_("Please wait %d seconds before using the %s command again."), Config->GetModule("memoserv")->Get<time_t>("senddelay"), source.command.c_str());
59  else if (result == MemoServService::MEMO_TARGET_FULL)
60  source.Reply(_("Sorry, %s currently has too many memos and cannot receive more."), nick.c_str());
61  else
62  {
63  source.Reply(_("Memo sent to \002%s\002."), nick.c_str());
64 
65  bool ischan;
66  MemoInfo *mi = MemoInfo::GetMemoInfo(nick, ischan);
67  if (mi == NULL)
68  throw CoreException("NULL mi in ms_rsend");
69  Memo *m = (mi->memos->size() ? mi->GetMemo(mi->memos->size() - 1) : NULL);
70  if (m != NULL)
71  m->receipt = true;
72  }
73  }
74  }
75 
76  bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
77  {
78  this->SendSyntax(source);
79  source.Reply(" ");
80  source.Reply(_("Sends the named \037nick\037 or \037channel\037 a memo containing\n"
81  "\037memo-text\037. When sending to a nickname, the recipient will\n"
82  "receive a notice that he/she has a new memo. The target\n"
83  "nickname/channel must be registered.\n"
84  "Once the memo is read by its recipient, an automatic notification\n"
85  "memo will be sent to the sender informing him/her that the memo\n"
86  "has been read."));
87  return true;
88  }
89 };
90 
91 class MSRSend : public Module
92 {
94 
95  public:
96  MSRSend(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
97  commandmsrsend(this)
98  {
99  if (!memoserv)
100  throw ModuleException("No MemoServ!");
101  }
102 };
103 
Serialize::Reference< NickCore > nc
Definition: account.h:47
CoreExport bool ReadOnly
Definition: main.cpp:28
static NickAlias * Find(const Anope::string &nick)
Definition: nickalias.cpp:121
CommandMSRSend commandmsrsend
Definition: ms_rsend.cpp:93
#define ACCESS_DENIED
Definition: language.h:73
static MemoInfo * GetMemoInfo(const Anope::string &targ, bool &is_chan)
Definition: memos.cpp:114
MSRSend(const Anope::string &modname, const Anope::string &creator)
Definition: ms_rsend.cpp:96
void SetDesc(const Anope::string &d)
Definition: command.cpp:130
bool receipt
Definition: memo.h:23
Definition: Config.cs:26
Definition: memo.h:40
Definition: memo.h:19
#define MEMO_SEND_DISABLED
Definition: language.h:117
static ServiceReference< MemoServService > memoserv("MemoServService","MemoServ")
Memo * GetMemo(unsigned index) const
Definition: memos.cpp:82
#define anope_override
Definition: services.h:56
#define MODULE_INIT(x)
Definition: modules.h:45
void SetSyntax(const Anope::string &s)
Definition: command.cpp:140
Serialize::Checker< std::vector< Memo * > > memos
Definition: memo.h:43
bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
Definition: ms_rsend.cpp:76
void SendSyntax(CommandSource &)
Definition: command.cpp:145
void Execute(CommandSource &source, const std::vector< Anope::string > &params) anope_override
Definition: ms_rsend.cpp:28
const char * c_str() const
Definition: anope.h:117
#define _(x)
Definition: services.h:50
CommandMSRSend(Module *creator)
Definition: ms_rsend.cpp:22