anope

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

ms_cancel.cpp (2248B)

      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 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 		{
     38 			source.Reply(ischan ? CHAN_X_NOT_REGISTERED : NICK_X_NOT_REGISTERED, nname.c_str());
     39 			return;
     40 		}
     41 
     42 		ChannelInfo *ci = NULL;
     43 		NickAlias *na = NULL;
     44 		if (ischan)
     45 		{
     46 			ci = ChannelInfo::Find(nname);
     47 
     48 			if (ci == NULL)
     49 				return; // can't happen
     50 		}
     51 		else
     52 		{
     53 			na = NickAlias::Find(nname);
     54 
     55 			if (na == NULL)
     56 				return; // can't happen
     57 		}
     58 
     59 		for (int i = mi->memos->size() - 1; i >= 0; --i)
     60 		{
     61 			Memo *m = mi->GetMemo(i);
     62 
     63 			if (!m->unread)
     64 				continue;
     65 
     66 			NickAlias *sender = NickAlias::Find(m->sender);
     67 
     68 			if (sender && sender->nc == source.GetAccount())
     69 			{
     70 				FOREACH_MOD(OnMemoDel, (ischan ? ci->name : na->nc->display, mi, m));
     71 				mi->Del(i);
     72 				source.Reply(_("Last memo to \002%s\002 has been cancelled."), (ischan ? ci->name : na->nc->display).c_str());
     73 				return;
     74 			}
     75 		}
     76 
     77 		source.Reply(_("No memo was cancelable."));
     78 	}
     79 
     80 	bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
     81 	{
     82 		this->SendSyntax(source);
     83 		source.Reply(" ");
     84 		source.Reply(_("Cancels the last memo you sent to the given nick or channel,\n"
     85 				"provided it has not been read at the time you use the command."));
     86 		return true;
     87 	}
     88 };
     89 
     90 class MSCancel : public Module
     91 {
     92 	CommandMSCancel commandmscancel;
     93 
     94  public:
     95 	MSCancel(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
     96 		commandmscancel(this)
     97 	{
     98 	}
     99 };
    100 
    101 MODULE_INIT(MSCancel)