anope- supernets anope source code & configuration |
git clone git://git.acid.vegas/anope.git |
Log | Files | Refs | Archive | README |
ms_del.cpp (4089B)
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 MemoDelCallback : public NumberList 15 { 16 CommandSource &source; 17 Command *cmd; 18 ChannelInfo *ci; 19 MemoInfo *mi; 20 public: 21 MemoDelCallback(CommandSource &_source, Command *c, ChannelInfo *_ci, MemoInfo *_mi, const Anope::string &list) : NumberList(list, true), source(_source), cmd(c), ci(_ci), mi(_mi) 22 { 23 } 24 25 void HandleNumber(unsigned number) anope_override 26 { 27 if (!number || number > mi->memos->size()) 28 return; 29 30 FOREACH_MOD(OnMemoDel, (ci ? ci->name : source.nc->display, mi, mi->GetMemo(number - 1))); 31 32 mi->Del(number - 1); 33 source.Reply(_("Memo %d has been deleted."), number); 34 if (ci) 35 Log(LOG_COMMAND, source, cmd, ci) << "on memo " << number; 36 } 37 }; 38 39 class CommandMSDel : public Command 40 { 41 public: 42 CommandMSDel(Module *creator) : Command(creator, "memoserv/del", 0, 2) 43 { 44 this->SetDesc(_("Delete a memo or memos")); 45 this->SetSyntax(_("[\037channel\037] {\037num\037 | \037list\037 | LAST | ALL}")); 46 } 47 48 void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override 49 { 50 if (Anope::ReadOnly) 51 { 52 source.Reply(READ_ONLY_MODE); 53 return; 54 } 55 56 MemoInfo *mi; 57 ChannelInfo *ci = NULL; 58 Anope::string numstr = !params.empty() ? params[0] : "", chan; 59 60 if (!numstr.empty() && numstr[0] == '#') 61 { 62 chan = numstr; 63 numstr = params.size() > 1 ? params[1] : ""; 64 65 ci = ChannelInfo::Find(chan); 66 if (!ci) 67 { 68 source.Reply(CHAN_X_NOT_REGISTERED, chan.c_str()); 69 return; 70 } 71 else if (!source.AccessFor(ci).HasPriv("MEMO")) 72 { 73 source.Reply(ACCESS_DENIED); 74 return; 75 } 76 mi = &ci->memos; 77 } 78 else 79 mi = &source.nc->memos; 80 if (numstr.empty() || (!isdigit(numstr[0]) && !numstr.equals_ci("ALL") && !numstr.equals_ci("LAST"))) 81 this->OnSyntaxError(source, numstr); 82 else if (mi->memos->empty()) 83 { 84 if (!chan.empty()) 85 source.Reply(MEMO_X_HAS_NO_MEMOS, chan.c_str()); 86 else 87 source.Reply(MEMO_HAVE_NO_MEMOS); 88 } 89 else 90 { 91 if (isdigit(numstr[0])) 92 { 93 MemoDelCallback list(source, this, ci, mi, numstr); 94 list.Process(); 95 } 96 else if (numstr.equals_ci("LAST")) 97 { 98 /* Delete last memo. */ 99 FOREACH_MOD(OnMemoDel, (ci ? ci->name : source.nc->display, mi, mi->GetMemo(mi->memos->size() - 1))); 100 mi->Del(mi->memos->size() - 1); 101 source.Reply(_("Memo %d has been deleted."), mi->memos->size() + 1); 102 if (ci) 103 Log(LOG_COMMAND, source, this, ci) << "on LAST memo"; 104 } 105 else 106 { 107 /* Delete all memos. */ 108 for (unsigned i = mi->memos->size(); i > 0; --i) 109 { 110 FOREACH_MOD(OnMemoDel, (ci ? ci->name : source.nc->display, mi, mi->GetMemo(i))); 111 mi->Del(i - 1); 112 } 113 if (!chan.empty()) 114 { 115 source.Reply(_("All memos for channel %s have been deleted."), chan.c_str()); 116 Log(LOG_COMMAND, source, this, ci) << "on ALL memos"; 117 } 118 else 119 source.Reply(_("All of your memos have been deleted.")); 120 } 121 } 122 return; 123 } 124 125 bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override 126 { 127 this->SendSyntax(source); 128 source.Reply(" "); 129 source.Reply(_("Deletes the specified memo or memos. You can supply\n" 130 "multiple memo numbers or ranges of numbers instead of a\n" 131 "single number, as in the second example below.\n" 132 " \n" 133 "If \002LAST\002 is given, the last memo will be deleted.\n" 134 "If \002ALL\002 is given, deletes all of your memos.\n" 135 " \n" 136 "Examples:\n" 137 " \n" 138 " \002DEL 1\002\n" 139 " Deletes your first memo.\n" 140 " \n" 141 " \002DEL 2-5,7-9\002\n" 142 " Deletes memos numbered 2 through 5 and 7 through 9.")); 143 return true; 144 } 145 }; 146 147 class MSDel : public Module 148 { 149 CommandMSDel commandmsdel; 150 151 public: 152 MSDel(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), 153 commandmsdel(this) 154 { 155 156 } 157 }; 158 159 MODULE_INIT(MSDel)