00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "module.h"
00015
00016 class CommandMSInfo : public Command
00017 {
00018 public:
00019 CommandMSInfo(Module *creator) : Command(creator, "memoserv/info", 0, 1)
00020 {
00021 this->SetDesc(_("Displays information about your memos"));
00022 this->SetSyntax(_("[\037nick\037 | \037channel\037]"));
00023 }
00024
00025 void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override
00026 {
00027 NickCore *nc = source.nc;
00028 const MemoInfo *mi;
00029 const NickAlias *na = NULL;
00030 ChannelInfo *ci = NULL;
00031 const Anope::string &nname = !params.empty() ? params[0] : "";
00032 int hardmax = 0;
00033
00034 if (!nname.empty() && nname[0] != '#' && source.HasPriv("memoserv/info"))
00035 {
00036 na = NickAlias::Find(nname);
00037 if (!na)
00038 {
00039 source.Reply(NICK_X_NOT_REGISTERED, nname.c_str());
00040 return;
00041 }
00042 mi = &na->nc->memos;
00043 hardmax = na->nc->HasExt("MEMO_HARDMAX") ? 1 : 0;
00044 }
00045 else if (!nname.empty() && nname[0] == '#')
00046 {
00047 ci = ChannelInfo::Find(nname);
00048 if (!ci)
00049 {
00050 source.Reply(CHAN_X_NOT_REGISTERED, nname.c_str());
00051 return;
00052 }
00053 else if (!source.AccessFor(ci).HasPriv("MEMO"))
00054 {
00055 source.Reply(ACCESS_DENIED);
00056 return;
00057 }
00058 mi = &ci->memos;
00059 hardmax = ci->HasExt("MEMO_HARDMAX") ? 1 : 0;
00060 }
00061 else if (!nname.empty())
00062 {
00063 source.Reply(ACCESS_DENIED);
00064 return;
00065 }
00066 else
00067 {
00068 mi = &nc->memos;
00069 hardmax = nc->HasExt("MEMO_HARDMAX") ? 1 : 0;
00070 }
00071
00072 if (!nname.empty() && (ci || na->nc != nc))
00073 {
00074 if (mi->memos->empty())
00075 source.Reply(_("%s currently has no memos."), nname.c_str());
00076 else if (mi->memos->size() == 1)
00077 {
00078 if (mi->GetMemo(0)->unread)
00079 source.Reply(_("%s currently has \0021\002 memo, and it has not yet been read."), nname.c_str());
00080 else
00081 source.Reply(_("%s currently has \0021\002 memo."), nname.c_str());
00082 }
00083 else
00084 {
00085 unsigned count = 0, i, end;
00086 for (i = 0, end = mi->memos->size(); i < end; ++i)
00087 if (mi->GetMemo(i)->unread)
00088 ++count;
00089 if (count == mi->memos->size())
00090 source.Reply(_("%s currently has \002%d\002 memos; all of them are unread."), nname.c_str(), count);
00091 else if (!count)
00092 source.Reply(_("%s currently has \002%d\002 memos."), nname.c_str(), mi->memos->size());
00093 else if (count == 1)
00094 source.Reply(_("%s currently has \002%d\002 memos, of which \0021\002 is unread."), nname.c_str(), mi->memos->size());
00095 else
00096 source.Reply(_("%s currently has \002%d\002 memos, of which \002%d\002 are unread."), nname.c_str(), mi->memos->size(), count);
00097 }
00098 if (!mi->memomax)
00099 {
00100 if (hardmax)
00101 source.Reply(_("%s's memo limit is \002%d\002, and may not be changed."), nname.c_str(), mi->memomax);
00102 else
00103 source.Reply(_("%s's memo limit is \002%d\002."), nname.c_str(), mi->memomax);
00104 }
00105 else if (mi->memomax > 0)
00106 {
00107 if (hardmax)
00108 source.Reply(_("%s's memo limit is \002%d\002, and may not be changed."), nname.c_str(), mi->memomax);
00109 else
00110 source.Reply(_("%s's memo limit is \002%d\002."), nname.c_str(), mi->memomax);
00111 }
00112 else
00113 source.Reply(_("%s has no memo limit."), nname.c_str());
00114
00115
00116
00117 if (na)
00118 {
00119 if (na->nc->HasExt("MEMO_RECEIVE") && na->nc->HasExt("MEMO_SIGNON"))
00120 source.Reply(_("%s is notified of new memos at logon and when they arrive."), nname.c_str());
00121 else if (na->nc->HasExt("MEMO_RECEIVE"))
00122 source.Reply(_("%s is notified when new memos arrive."), nname.c_str());
00123 else if (na->nc->HasExt("MEMO_SIGNON"))
00124 source.Reply(_("%s is notified of news memos at logon."), nname.c_str());
00125 else
00126 source.Reply(_("%s is not notified of new memos."), nname.c_str());
00127 }
00128 }
00129 else
00130 {
00131 if (mi->memos->empty())
00132 source.Reply(_("You currently have no memos."));
00133 else if (mi->memos->size() == 1)
00134 {
00135 if (mi->GetMemo(0)->unread)
00136 source.Reply(_("You currently have \0021\002 memo, and it has not yet been read."));
00137 else
00138 source.Reply(_("You currently have \0021\002 memo."));
00139 }
00140 else
00141 {
00142 unsigned count = 0, i, end;
00143 for (i = 0, end = mi->memos->size(); i < end; ++i)
00144 if (mi->GetMemo(i)->unread)
00145 ++count;
00146 if (count == mi->memos->size())
00147 source.Reply(_("You currently have \002%d\002 memos; all of them are unread."), count);
00148 else if (!count)
00149 source.Reply(_("You currently have \002%d\002 memos."), mi->memos->size());
00150 else if (count == 1)
00151 source.Reply(_("You currently have \002%d\002 memos, of which \0021\002 is unread."), mi->memos->size());
00152 else
00153 source.Reply(_("You currently have \002%d\002 memos, of which \002%d\002 are unread."), mi->memos->size(), count);
00154 }
00155
00156 if (!mi->memomax)
00157 {
00158 if (!source.IsServicesOper() && hardmax)
00159 source.Reply(_("Your memo limit is \0020\002; you will not receive any new memos. You cannot change this limit."));
00160 else
00161 source.Reply(_("Your memo limit is \0020\002; you will not receive any new memos."));
00162 }
00163 else if (mi->memomax > 0)
00164 {
00165 if (!source.IsServicesOper() && hardmax)
00166 source.Reply(_("Your memo limit is \002%d\002, and may not be changed."), mi->memomax);
00167 else
00168 source.Reply(_("Your memo limit is \002%d\002."), mi->memomax);
00169 }
00170 else
00171 source.Reply(_("You have no limit on the number of memos you may keep."));
00172
00173
00174 if (nc->HasExt("MEMO_RECEIVE") && nc->HasExt("MEMO_SIGNON"))
00175 source.Reply(_("You will be notified of new memos at logon and when they arrive."));
00176 else if (nc->HasExt("MEMO_RECEIVE"))
00177 source.Reply(_("You will be notified when new memos arrive."));
00178 else if (nc->HasExt("MEMO_SIGNON"))
00179 source.Reply(_("You will be notified of new memos at logon."));
00180 else
00181 source.Reply(_("You will not be notified of new memos."));
00182 }
00183 return;
00184 }
00185
00186 bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
00187 {
00188 this->SendSyntax(source);
00189 source.Reply(" ");
00190 source.Reply(_("Without a parameter, displays information on the number of\n"
00191 "memos you have, how many of them are unread, and how many\n"
00192 "total memos you can receive.\n"
00193 " \n"
00194 "With a channel parameter, displays the same information for\n"
00195 "the given channel.\n"
00196 " \n"
00197 "With a nickname parameter, displays the same information\n"
00198 "for the given nickname. This is limited to \002Services\002\n"
00199 "\002Operators\002."));
00200
00201 return true;
00202 }
00203 };
00204
00205 class MSInfo : public Module
00206 {
00207 CommandMSInfo commandmsinfo;
00208
00209 public:
00210 MSInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE),
00211 commandmsinfo(this)
00212 {
00213 this->SetAuthor("Anope");
00214
00215 }
00216 };
00217
00218 MODULE_INIT(MSInfo)