Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "module.h"
00015 #include "memoserv.h"
00016
00017 static ServiceReference<MemoServService> MemoServService("MemoServService", "MemoServ");
00018
00019 class CommandMSCancel : public Command
00020 {
00021 public:
00022 CommandMSCancel(Module *creator) : Command(creator, "memoserv/cancel", 1, 1)
00023 {
00024 this->SetDesc(_("Cancel the last memo you sent"));
00025 this->SetSyntax(_("{\037nick\037 | \037channel\037}"));
00026 }
00027
00028 void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override
00029 {
00030 if (!MemoServService)
00031 return;
00032
00033
00034 const Anope::string &nname = params[0];
00035
00036 bool ischan;
00037 MemoInfo *mi = MemoInfo::GetMemoInfo(nname, ischan);
00038
00039 if (mi == NULL)
00040 source.Reply(ischan ? CHAN_X_NOT_REGISTERED : _(NICK_X_NOT_REGISTERED), nname.c_str());
00041 else
00042 {
00043 ChannelInfo *ci = NULL;
00044 NickAlias *na = NULL;
00045 if (ischan)
00046 ci = ChannelInfo::Find(nname);
00047 else
00048 na = NickAlias::Find(nname);
00049 for (int i = mi->memos->size() - 1; i >= 0; --i)
00050 if (mi->GetMemo(i)->unread && source.nc->display.equals_ci(mi->GetMemo(i)->sender))
00051 {
00052 if (ischan)
00053 FOREACH_MOD(I_OnMemoDel, OnMemoDel(ci, mi, mi->GetMemo(i)));
00054 else
00055 FOREACH_MOD(I_OnMemoDel, OnMemoDel(na->nc, mi, mi->GetMemo(i)));
00056 mi->Del(i);
00057 source.Reply(_("Last memo to \002%s\002 has been cancelled."), nname.c_str());
00058 return;
00059 }
00060
00061 source.Reply(_("No memo was cancelable."));
00062 }
00063 return;
00064 }
00065
00066 bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
00067 {
00068 this->SendSyntax(source);
00069 source.Reply(" ");
00070 source.Reply(_("Cancels the last memo you sent to the given nick or channel,\n"
00071 "provided it has not been read at the time you use the command."));
00072 return true;
00073 }
00074 };
00075
00076 class MSCancel : public Module
00077 {
00078 CommandMSCancel commandmscancel;
00079
00080 public:
00081 MSCancel(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE),
00082 commandmscancel(this)
00083 {
00084 this->SetAuthor("Anope");
00085
00086 if (!MemoServService)
00087 throw ModuleException("No MemoServ!");
00088 }
00089 };
00090
00091 MODULE_INIT(MSCancel)