cs_info.cpp

Go to the documentation of this file.
00001 /* ChanServ core functions
00002  *
00003  * (C) 2003-2013 Anope Team
00004  * Contact us at team@anope.org
00005  *
00006  * Please read COPYING and README for further details.
00007  *
00008  * Based on the original code of Epona by Lara.
00009  * Based on the original code of Services by Andy Church.
00010  */
00011 
00012 /*************************************************************************/
00013 
00014 #include "module.h"
00015 
00016 class CommandCSInfo : public Command
00017 {
00018         void CheckOptStr(Anope::string &buf, const Anope::string &opt, const char *str, const ChannelInfo *ci, const NickCore *nc)
00019         {
00020                 if (ci->HasExt(opt))
00021                 {
00022                         if (!buf.empty())
00023                                 buf += ", ";
00024 
00025                         buf += Language::Translate(nc, str);
00026                 }
00027         }
00028 
00029  public:
00030         CommandCSInfo(Module *creator) : Command(creator, "chanserv/info", 1, 2)
00031         {
00032                 this->SetDesc(_("Lists information about the named registered channel"));
00033                 this->SetSyntax(_("\037channel\037"));
00034                 this->AllowUnregistered(true);
00035         }
00036 
00037         void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
00038         {
00039                 const Anope::string &chan = params[0];
00040 
00041                 NickCore *nc = source.nc;
00042                 ChannelInfo *ci = ChannelInfo::Find(params[0]);
00043                 if (ci == NULL)
00044                 {
00045                         source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str());
00046                         return;
00047                 }
00048 
00049                 bool has_auspex = source.HasPriv("chanserv/auspex");
00050                 bool show_all = false;
00051 
00052                 /* Should we show all fields? Only for sadmins and identified users */
00053                 if (has_auspex || source.AccessFor(ci).HasPriv("INFO"))
00054                         show_all = true;
00055 
00056                 InfoFormatter info(nc);
00057 
00058                 source.Reply(CHAN_INFO_HEADER, chan.c_str());
00059                 if (ci->GetFounder())
00060                         info["Founder"] = ci->GetFounder()->display;
00061 
00062                 if (show_all && ci->GetSuccessor())
00063                         info["Successor"] = ci->GetSuccessor()->display;
00064 
00065                 if (!ci->desc.empty())
00066                         info["Description"] = ci->desc;
00067 
00068                 info["Registered"] = Anope::strftime(ci->time_registered);
00069                 info["Last used"] = Anope::strftime(ci->last_used);
00070 
00071                 const ModeLock *secret = ci->GetMLock("SECRET");
00072                 if (!ci->last_topic.empty() && (show_all || ((!secret || secret->set == false) && (!ci->c || !ci->c->HasMode("SECRET")))))
00073                 {
00074                         info["Last topic"] = ci->last_topic;
00075                         info["Topic set by"] = ci->last_topic_setter;
00076                 }
00077 
00078                 if (show_all)
00079                 {
00080                         info["Ban type"] = stringify(ci->bantype);
00081 
00082                         Anope::string optbuf;
00083                         CheckOptStr(optbuf, "KEEPTOPIC", _("Topic Retention"), ci, nc);
00084                         CheckOptStr(optbuf, "PEACE", _("Peace"), ci, nc);
00085                         CheckOptStr(optbuf, "PRIVATE", _("Private"), ci, nc);
00086                         CheckOptStr(optbuf, "RESTRICTED", _("Restricted Access"), ci, nc);
00087                         CheckOptStr(optbuf, "SECURE", _("Secure"), ci, nc);
00088                         CheckOptStr(optbuf, "SECUREFOUNDER", _("Secure Founder"), ci, nc);
00089                         CheckOptStr(optbuf, "SECUREOPS", _("Secure Ops"), ci, nc);
00090                         if (ci->HasExt("SIGNKICK"))
00091                                 CheckOptStr(optbuf, "SIGNKICK", _("Signed kicks"), ci, nc);
00092                         else
00093                                 CheckOptStr(optbuf, "SIGNKICK_LEVEL", _("Signed kicks"), ci, nc);
00094                         CheckOptStr(optbuf, "TOPICLOCK", _("Topic Lock"), ci, nc);
00095                         CheckOptStr(optbuf, "PERSIST", _("Persistent"), ci, nc);
00096                         CheckOptStr(optbuf, "NO_EXPIRE", _("No expire"), ci, nc);
00097                         CheckOptStr(optbuf, "STATS", _("Chanstats"), ci, nc);
00098 
00099                         info["Options"] = optbuf.empty() ? _("None") : optbuf;
00100 
00101                         const Anope::string &ml = ci->GetMLockAsString(true);
00102                         if (!ml.empty())
00103                                 info["Mode lock"] = ml;
00104 
00105                         if (!ci->HasExt("NO_EXPIRE"))
00106                                 info["Expires on"] = Anope::strftime(ci->last_used + Config->CSExpire);
00107                 }
00108                 if (ci->HasExt("SUSPENDED"))
00109                 {
00110                         Anope::string *by = ci->GetExt<ExtensibleItemClass<Anope::string> *>("suspend_by"), *reason = ci->GetExt<ExtensibleItemClass<Anope::string> *>("suspend_reason");
00111                         if (by != NULL)
00112                                 info["Suspended"] = Anope::printf("[%s] %s", by->c_str(), (reason && !reason->empty() ? reason->c_str() : NO_REASON));
00113                 }
00114 
00115                 FOREACH_MOD(I_OnChanInfo, OnChanInfo(source, ci, info, show_all));
00116 
00117                 std::vector<Anope::string> replies;
00118                 info.Process(replies);
00119 
00120                 for (unsigned i = 0; i < replies.size(); ++i)
00121                         source.Reply(replies[i]);
00122 
00123                 return;
00124         }
00125 
00126         bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
00127         {
00128                 this->SendSyntax(source);
00129                 source.Reply(" ");
00130                 source.Reply(_("Lists information about the named registered channel,\n"
00131                                 "including its founder, time of registration, and last\n"
00132                                 "time used. If the user issuing the command has the\n"
00133                                 "appropriate access for it, then the description, successor,\n"
00134                                 "last topic set, settings and expiration time will also\n"
00135                                 "be displayed when applicable."));
00136                 return true;
00137         }
00138 };
00139 
00140 class CSInfo : public Module
00141 {
00142         CommandCSInfo commandcsinfo;
00143 
00144  public:
00145         CSInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE),
00146                 commandcsinfo(this)
00147         {
00148                 this->SetAuthor("Anope");
00149 
00150         }
00151 };
00152 
00153 MODULE_INIT(CSInfo)