1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
/* MemoServ core functions
*
* (C) 2003-2016 Anope Team
* Contact us at team@anope.org
*
* Please read COPYING and README for further details.
*
* Based on the original code of Epona by Lara.
* Based on the original code of Services by Andy Church.
*/
#include "module.h"
class CommandMSList : public Command
{
public:
CommandMSList(Module *creator) : Command(creator, "memoserv/list", 0, 2)
{
this->SetDesc(_("List your memos"));
this->SetSyntax(_("[\037channel\037] [\037list\037 | NEW]"));
}
void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override
{
Anope::string param = !params.empty() ? params[0] : "", chan;
ChannelInfo *ci = NULL;
const MemoInfo *mi;
if (!param.empty() && param[0] == '#')
{
chan = param;
param = params.size() > 1 ? params[1] : "";
ci = ChannelInfo::Find(chan);
if (!ci)
{
source.Reply(CHAN_X_NOT_REGISTERED, chan.c_str());
return;
}
else if (!source.AccessFor(ci).HasPriv("MEMO"))
{
source.Reply(ACCESS_DENIED);
return;
}
mi = &ci->memos;
}
else
mi = &source.nc->memos;
if (!param.empty() && !isdigit(param[0]) && !param.equals_ci("NEW"))
this->OnSyntaxError(source, param);
else if (!mi->memos->size())
{
if (!chan.empty())
source.Reply(MEMO_X_HAS_NO_MEMOS, chan.c_str());
else
source.Reply(MEMO_HAVE_NO_MEMOS);
}
else
{
ListFormatter list(source.GetAccount());
list.AddColumn(_("Number")).AddColumn(_("Sender")).AddColumn(_("Date/Time"));
if (!param.empty() && isdigit(param[0]))
{
class MemoListCallback : public NumberList
{
ListFormatter &list;
CommandSource &source;
const MemoInfo *mi;
public:
MemoListCallback(ListFormatter &_list, CommandSource &_source, const MemoInfo *_mi, const Anope::string &numlist) : NumberList(numlist, false), list(_list), source(_source), mi(_mi)
{
}
void HandleNumber(unsigned number) anope_override
{
if (!number || number > mi->memos->size())
return;
const Memo *m = mi->GetMemo(number - 1);
ListFormatter::ListEntry entry;
entry["Number"] = (m->unread ? "* " : " ") + stringify(number);
entry["Sender"] = m->sender;
entry["Date/Time"] = Anope::strftime(m->time, source.GetAccount());
this->list.AddEntry(entry);
}
}
mlc(list, source, mi, param);
mlc.Process();
}
else
{
if (!param.empty())
{
unsigned i, end;
for (i = 0, end = mi->memos->size(); i < end; ++i)
if (mi->GetMemo(i)->unread)
break;
if (i == end)
{
if (!chan.empty())
source.Reply(MEMO_X_HAS_NO_NEW_MEMOS, chan.c_str());
else
source.Reply(MEMO_HAVE_NO_NEW_MEMOS);
return;
}
}
for (unsigned i = 0, end = mi->memos->size(); i < end; ++i)
{
if (!param.empty() && !mi->GetMemo(i)->unread)
continue;
const Memo *m = mi->GetMemo(i);
ListFormatter::ListEntry entry;
entry["Number"] = (m->unread ? "* " : " ") + stringify(i + 1);
entry["Sender"] = m->sender;
entry["Date/Time"] = Anope::strftime(m->time, source.GetAccount());
list.AddEntry(entry);
}
}
std::vector<Anope::string> replies;
list.Process(replies);
source.Reply(_("Memos for %s:"), ci ? ci->name.c_str() : source.GetNick().c_str());
for (unsigned i = 0; i < replies.size(); ++i)
source.Reply(replies[i]);
}
return;
}
bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
{
this->SendSyntax(source);
source.Reply(" ");
source.Reply(_("Lists any memos you currently have. With \002NEW\002, lists only\n"
"new (unread) memos. Unread memos are marked with a \"*\"\n"
"to the left of the memo number. You can also specify a list\n"
"of numbers, as in the example below:\n"
" \002LIST 2-5,7-9\002\n"
" Lists memos numbered 2 through 5 and 7 through 9."));
return true;
}
};
class MSList : public Module
{
CommandMSList commandmslist;
public:
MSList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandmslist(this)
{
}
};
MODULE_INIT(MSList)
|