Anope IRC Services  Version 2.0
ms_cancel.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 class CommandMSCancel : public Command
15 {
16  public:
17  CommandMSCancel(Module *creator) : Command(creator, "memoserv/cancel", 1, 1)
18  {
19  this->SetDesc(_("Cancel the last memo you sent"));
20  this->SetSyntax(_("{\037nick\037 | \037channel\037}"));
21  }
22 
23  void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
24  {
25  if (Anope::ReadOnly)
26  {
27  source.Reply(READ_ONLY_MODE);
28  return;
29  }
30 
31  const Anope::string &nname = params[0];
32 
33  bool ischan;
34  MemoInfo *mi = MemoInfo::GetMemoInfo(nname, ischan);
35 
36  if (mi == NULL)
37  source.Reply(ischan ? CHAN_X_NOT_REGISTERED : _(NICK_X_NOT_REGISTERED), nname.c_str());
38  else
39  {
40  ChannelInfo *ci = NULL;
41  NickAlias *na = NULL;
42  if (ischan)
43  ci = ChannelInfo::Find(nname);
44  else
45  na = NickAlias::Find(nname);
46  for (int i = mi->memos->size() - 1; i >= 0; --i)
47  if (mi->GetMemo(i)->unread && source.nc->display.equals_ci(mi->GetMemo(i)->sender))
48  {
49  FOREACH_MOD(OnMemoDel, (ischan ? ci->name : na->nc->display, mi, mi->GetMemo(i)));
50  mi->Del(i);
51  source.Reply(_("Last memo to \002%s\002 has been cancelled."), nname.c_str());
52  return;
53  }
54 
55  source.Reply(_("No memo was cancelable."));
56  }
57  return;
58  }
59 
60  bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
61  {
62  this->SendSyntax(source);
63  source.Reply(" ");
64  source.Reply(_("Cancels the last memo you sent to the given nick or channel,\n"
65  "provided it has not been read at the time you use the command."));
66  return true;
67  }
68 };
69 
70 class MSCancel : public Module
71 {
73 
74  public:
75  MSCancel(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
76  commandmscancel(this)
77  {
78  }
79 };
80 
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
Definition: hashcomp.h:84
Anope::string name
Definition: regchannel.h:63
Anope::string sender
Definition: memo.h:33
#define NICK_X_NOT_REGISTERED
Definition: language.h:79
static MemoInfo * GetMemoInfo(const Anope::string &targ, bool &is_chan)
Definition: memos.cpp:114
#define READ_ONLY_MODE
Definition: language.h:71
void SetDesc(const Anope::string &d)
Definition: command.cpp:130
#define FOREACH_MOD(ename, args)
Definition: modules.h:62
static ChannelInfo * Find(const Anope::string &name)
Definition: regchannel.cpp:630
bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
Definition: ms_cancel.cpp:60
Definition: memo.h:40
void Execute(CommandSource &source, const std::vector< Anope::string > &params) anope_override
Definition: ms_cancel.cpp:23
Memo * GetMemo(unsigned index) const
Definition: memos.cpp:82
#define anope_override
Definition: services.h:56
#define MODULE_INIT(x)
Definition: modules.h:45
CommandMSCancel(Module *creator)
Definition: ms_cancel.cpp:17
void SetSyntax(const Anope::string &s)
Definition: command.cpp:140
CommandMSCancel commandmscancel
Definition: ms_cancel.cpp:72
#define CHAN_X_NOT_REGISTERED
Definition: language.h:84
Serialize::Checker< std::vector< Memo * > > memos
Definition: memo.h:43
void SendSyntax(CommandSource &)
Definition: command.cpp:145
MSCancel(const Anope::string &modname, const Anope::string &creator)
Definition: ms_cancel.cpp:75
const char * c_str() const
Definition: anope.h:117
void Del(unsigned index)
Definition: memos.cpp:99
bool unread
Definition: memo.h:22
#define _(x)
Definition: services.h:50