Anope IRC Services  Version 2.0
ms_check.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 CommandMSCheck : public Command
15 {
16  public:
17  CommandMSCheck(Module *creator) : Command(creator, "memoserv/check", 1, 1)
18  {
19  this->SetDesc(_("Checks if last memo to a nick was read"));
20  this->SetSyntax(_("\037nick\037"));
21  }
22 
23  void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
24  {
25 
26  const Anope::string &recipient = params[0];
27 
28  bool found = false;
29 
30  const NickAlias *na = NickAlias::Find(recipient);
31  if (!na)
32  {
33  source.Reply(NICK_X_NOT_REGISTERED, recipient.c_str());
34  return;
35  }
36 
37  MemoInfo *mi = &na->nc->memos;
38 
39  /* Okay, I know this looks strange but we wanna get the LAST memo, so we
40  have to loop backwards */
41 
42  for (unsigned i = mi->memos->size(); i > 0; --i)
43  {
44  Memo *m = mi->GetMemo(i - 1);
45  NickAlias *na2 = NickAlias::Find(m->sender);
46 
47  if (na2 != NULL && na2->nc == source.GetAccount())
48  {
49  found = true; /* Yes, we've found the memo */
50 
51  if (m->unread)
52  source.Reply(_("The last memo you sent to %s (sent on %s) has not yet been read."), na->nick.c_str(), Anope::strftime(m->time, source.GetAccount()).c_str());
53  else
54  source.Reply(_("The last memo you sent to %s (sent on %s) has been read."), na->nick.c_str(), Anope::strftime(m->time, source.GetAccount()).c_str());
55  break;
56  }
57  }
58 
59  if (!found)
60  source.Reply(_("Nick %s doesn't have a memo from you."), na->nick.c_str());
61 
62  return;
63  }
64 
65  bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
66  {
67  this->SendSyntax(source);
68  source.Reply(" ");
69  source.Reply(_("Checks whether the _last_ memo you sent to \037nick\037 has been read\n"
70  "or not. Note that this does only work with nicks, not with channels."));
71  return true;
72  }
73 };
74 
75 class MSCheck : public Module
76 {
78 
79  public:
80  MSCheck(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
81  commandmscheck(this)
82  {
83 
84  }
85 };
86 
Serialize::Reference< NickCore > nc
Definition: account.h:47
static NickAlias * Find(const Anope::string &nick)
Definition: nickalias.cpp:121
void Execute(CommandSource &source, const std::vector< Anope::string > &params) anope_override
Definition: ms_check.cpp:23
Anope::string nick
Definition: account.h:37
Anope::string sender
Definition: memo.h:33
MSCheck(const Anope::string &modname, const Anope::string &creator)
Definition: ms_check.cpp:80
#define NICK_X_NOT_REGISTERED
Definition: language.h:79
void SetDesc(const Anope::string &d)
Definition: command.cpp:130
CommandMSCheck(Module *creator)
Definition: ms_check.cpp:17
CommandMSCheck commandmscheck
Definition: ms_check.cpp:77
bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
Definition: ms_check.cpp:65
Definition: memo.h:40
Definition: memo.h:19
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
void SendSyntax(CommandSource &)
Definition: command.cpp:145
const char * c_str() const
Definition: anope.h:117
time_t time
Definition: memo.h:32
CoreExport Anope::string strftime(time_t t, const NickCore *nc=NULL, bool short_output=false)
Definition: misc.cpp:356
bool unread
Definition: memo.h:22
#define _(x)
Definition: services.h:50