void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { if (Anope::ReadOnly) { source.Reply(_("Services are in read-only mode.")); return; } MemoServ::MemoInfo *mi; ChanServ::Channel *ci = NULL; Anope::string numstr = !params.empty() ? params[0] : "", chan; if (!numstr.empty() && numstr[0] == '#') { chan = numstr; numstr = params.size() > 1 ? params[1] : ""; ci = ChanServ::Find(chan); if (!ci) { source.Reply(_("Channel \002{0}\002 isn't registered."), chan); return; } if (!source.AccessFor(ci).HasPriv("MEMO")) { source.Reply(_("Access denied. You do not have privilege \002{0}\002 on \002{1}\002."), "MEMO", ci->GetName()); return; } mi = ci->GetMemos(); } else { mi = source.nc->GetMemos(); } if (numstr.empty() || (!isdigit(numstr[0]) && !numstr.equals_ci("ALL") && !numstr.equals_ci("LAST"))) { this->OnSyntaxError(source, numstr); return; } if (!mi || mi->GetMemos().empty()) { if (!chan.empty()) source.Reply(_("\002{0}\002 has no memos."), chan); else source.Reply(_("You have no memos.")); return; } auto memos = mi->GetMemos(); if (isdigit(numstr[0])) { NumberList(numstr, true, [&](unsigned int number) { if (!number || number > memos.size()) return; EventManager::Get()->Dispatch(&MemoServ::Event::MemoDel::OnMemoDel, ci ? ci->GetName() : source.nc->GetDisplay(), mi, mi->GetMemo(number - 1)); mi->Del(number - 1); source.Reply(_("Memo \002{0}\002 has been deleted."), number); }, [](){}); } else if (numstr.equals_ci("LAST")) { /* Delete last memo. */ EventManager::Get()->Dispatch(&MemoServ::Event::MemoDel::OnMemoDel, ci ? ci->GetName() : source.nc->GetDisplay(), mi, mi->GetMemo(memos.size() - 1)); mi->Del(memos.size() - 1); source.Reply(_("Memo \002{0}\002 has been deleted."), memos.size() + 1); } else { /* Delete all memos. */ std::for_each(memos.begin(), memos.end(), [&](MemoServ::Memo *m) { EventManager::Get()->Dispatch(&MemoServ::Event::MemoDel::OnMemoDel, ci ? ci->GetName() : source.nc->GetDisplay(), mi, m); delete m; }); if (!chan.empty()) source.Reply(_("All memos for channel \002{0}\002 have been deleted."), chan); else source.Reply(_("All of your memos have been deleted.")); } }
void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { if (Anope::ReadOnly) { source.Reply(_("Services are in read-only mode.")); return; } const Anope::string &nname = params[0]; bool ischan, isregistered; MemoServ::MemoInfo *mi = MemoServ::service->GetMemoInfo(nname, ischan, isregistered, false); if (!isregistered) { if (ischan) source.Reply(_("Channel \002{0}\002 isn't registered."), nname); else source.Reply(_("\002{0}\002 isn't registered."), nname); return; } if (mi == nullptr) return; ChanServ::Channel *ci = NULL; NickServ::Nick *na = NULL; if (ischan) { ci = ChanServ::Find(nname); if (ci == nullptr) return; } else { na = NickServ::FindNick(nname); if (na == nullptr) return; } auto memos = mi->GetMemos(); for (int i = memos.size() - 1; i >= 0; --i) { MemoServ::Memo *m = memos[i]; if (!m->GetUnread()) continue; NickServ::Nick *sender = NickServ::FindNick(m->GetSender()); if (sender && sender->GetAccount() == source.GetAccount()) { EventManager::Get()->Dispatch(&MemoServ::Event::MemoDel::OnMemoDel, ischan ? ci->GetName() : na->GetAccount()->GetDisplay(), mi, m); mi->Del(i); source.Reply(_("Your last memo to \002{0}\002 has been cancelled."), ischan ? ci->GetName() : na->GetAccount()->GetDisplay()); return; } } source.Reply(_("No memo was cancelable.")); }