anope

- supernets anope source code & configuration
git clone git://git.acid.vegas/anope.git
Log | Files | Refs | Archive | README

ms_check.cpp (2245B)

      1 /* MemoServ core functions
      2  *
      3  * (C) 2003-2022 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 want to 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 only works with nicks, not with channels."));
     71 		return true;
     72 	}
     73 };
     74 
     75 class MSCheck : public Module
     76 {
     77 	CommandMSCheck commandmscheck;
     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 
     87 MODULE_INIT(MSCheck)