anope

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

ms_rsend.cpp (3197B)

      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 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);
     55 			if (result == MemoServService::MEMO_INVALID_TARGET)
     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 {
     93 	CommandMSRSend commandmsrsend;
     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 
    104 MODULE_INIT(MSRSend)