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
|
/* MemoServ core functions
*
* (C) 2003-2010 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 MemoListCallback : public NumberList
{
CommandSource &source;
MemoInfo *mi;
public:
MemoListCallback(CommandSource &_source, MemoInfo *_mi, const Anope::string &numlist) : NumberList(numlist, false), source(_source), mi(_mi)
{
}
void HandleNumber(unsigned Number)
{
if (!Number || Number > mi->memos.size())
return;
MemoListCallback::DoRead(source, mi, NULL, Number - 1);
}
static void DoRead(CommandSource &source, MemoInfo *mi, ChannelInfo *ci, unsigned index)
{
Memo *m = mi->memos[index];
if (ci)
source.Reply(MEMO_CHAN_HEADER, index + 1, m->sender.c_str(), do_strftime(m->time).c_str(), Config->s_MemoServ.c_str(), ci->name.c_str(), index + 1);
else
source.Reply(MEMO_HEADER, index + 1, m->sender.c_str(), do_strftime(m->time).c_str(), Config->s_MemoServ.c_str(), index + 1);
source.Reply(MEMO_TEXT, m->text.c_str());
m->UnsetFlag(MF_UNREAD);
/* Check if a receipt notification was requested */
if (m->HasFlag(MF_RECEIPT))
rsend_notify(source, m, ci ? ci->name : "");
}
};
class CommandMSRead : public Command
{
public:
CommandMSRead() : Command("READ", 0, 2)
{
}
CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms)
{
User *u = source.u;
MemoInfo *mi;
ChannelInfo *ci = NULL;
Anope::string numstr = !params.empty() ? params[0] : "", chan;
int num;
if (!numstr.empty() && numstr[0] == '#')
{
chan = numstr;
numstr = params.size() > 1 ? params[1] : "";
if (!(ci = cs_findchan(chan)))
{
source.Reply(CHAN_X_NOT_REGISTERED, chan.c_str());
return MOD_CONT;
}
else if (!check_access(u, ci, CA_MEMO))
{
source.Reply(ACCESS_DENIED);
return MOD_CONT;
}
mi = &ci->memos;
}
else
mi = &u->Account()->memos;
num = !numstr.empty() && numstr.is_number_only() ? convertTo<int>(numstr) : -1;
if (numstr.empty() || (!numstr.equals_ci("LAST") && !numstr.equals_ci("NEW") && num <= 0))
this->OnSyntaxError(source, numstr);
else if (mi->memos.empty())
{
if (!chan.empty())
source.Reply(MEMO_X_HAS_NO_MEMOS, chan.c_str());
else
source.Reply(MEMO_HAVE_NO_MEMOS);
}
else {
int i, end;
if (numstr.equals_ci("NEW"))
{
int readcount = 0;
for (i = 0, end = mi->memos.size(); i < end; ++i)
if (mi->memos[i]->HasFlag(MF_UNREAD))
{
MemoListCallback::DoRead(source, mi, ci, i);
++readcount;
}
if (!readcount)
{
if (!chan.empty())
source.Reply(MEMO_X_HAS_NO_NEW_MEMOS, chan.c_str());
else
source.Reply(MEMO_HAVE_NO_NEW_MEMOS);
}
}
else if (numstr.equals_ci("LAST"))
{
for (i = 0, end = mi->memos.size() - 1; i < end; ++i);
MemoListCallback::DoRead(source, mi, ci, i);
}
else /* number[s] */
{
MemoListCallback list(source, mi, numstr);
list.Process();
}
}
return MOD_CONT;
}
bool OnHelp(CommandSource &source, const Anope::string &subcommand)
{
source.Reply(MEMO_HELP_READ);
return true;
}
void OnSyntaxError(CommandSource &source, const Anope::string &subcommand)
{
SyntaxError(source, "READ", MEMO_READ_SYNTAX);
}
void OnServHelp(CommandSource &source)
{
source.Reply(MEMO_HELP_CMD_READ);
}
};
class MSRead : public Module
{
CommandMSRead commandmsread;
public:
MSRead(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator)
{
this->SetAuthor("Anope");
this->SetType(CORE);
this->AddCommand(MemoServ, &commandmsread);
}
};
MODULE_INIT(MSRead)
|