Anope IRC Services  Version 2.0
cs_info.cpp
Go to the documentation of this file.
1 /* ChanServ core functions
2  *
3  * (C) 2003-2014 Anope Team
4  * Contact us at team@anope.org
5  *
6  * Please read COPYING and README for further details.
7  *
8  * Based on the original code of Epona by Lara.
9  * Based on the original code of Services by Andy Church.
10  */
11 
12 #include "module.h"
13 
14 class CommandCSInfo : public Command
15 {
16  public:
17  CommandCSInfo(Module *creator) : Command(creator, "chanserv/info", 1, 2)
18  {
19  this->SetDesc(_("Lists information about the named registered channel"));
20  this->SetSyntax(_("\037channel\037"));
21  this->AllowUnregistered(true);
22  }
23 
24  void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
25  {
26  const Anope::string &chan = params[0];
27 
28  NickCore *nc = source.nc;
29  ChannelInfo *ci = ChannelInfo::Find(params[0]);
30  if (ci == NULL)
31  {
32  source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str());
33  return;
34  }
35 
36  bool has_auspex = source.HasPriv("chanserv/auspex");
37  bool show_all = false;
38 
39  /* Should we show all fields? Only for sadmins and identified users */
40  if (source.AccessFor(ci).HasPriv("INFO") || has_auspex)
41  show_all = true;
42 
43  InfoFormatter info(nc);
44 
45  source.Reply(CHAN_INFO_HEADER, chan.c_str());
46  if (ci->GetFounder())
47  info[_("Founder")] = ci->GetFounder()->display;
48 
49  if (show_all && ci->GetSuccessor())
50  info[_("Successor")] = ci->GetSuccessor()->display;
51 
52  if (!ci->desc.empty())
53  info[_("Description")] = ci->desc;
54 
55  info[_("Registered")] = Anope::strftime(ci->time_registered, source.GetAccount());
56  info[_("Last used")] = Anope::strftime(ci->last_used, source.GetAccount());
57 
58  if (show_all)
59  {
60  info[_("Ban type")] = stringify(ci->bantype);
61  }
62 
63  FOREACH_MOD(OnChanInfo, (source, ci, info, show_all));
64 
65  std::vector<Anope::string> replies;
66  info.Process(replies);
67 
68  for (unsigned i = 0; i < replies.size(); ++i)
69  source.Reply(replies[i]);
70  }
71 
72  bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
73  {
74  this->SendSyntax(source);
75  source.Reply(" ");
76  source.Reply(_("Lists information about the named registered channel,\n"
77  "including its founder, time of registration, and last\n"
78  "time used. If the user issuing the command has the\n"
79  "appropriate access for it, then the description, successor,\n"
80  "last topic set, settings and expiration time will also\n"
81  "be displayed when applicable."));
82  return true;
83  }
84 };
85 
86 class CSInfo : public Module
87 {
89 
90  public:
91  CSInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
92  commandcsinfo(this)
93  {
94 
95  }
96 };
97 
Definition: hashcomp.h:84
Anope::string desc
Definition: regchannel.h:64
bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
Definition: cs_info.cpp:72
NickCore * GetSuccessor() const
Definition: regchannel.cpp:378
void SetDesc(const Anope::string &d)
Definition: command.cpp:130
#define FOREACH_MOD(ename, args)
Definition: modules.h:62
static ChannelInfo * Find(const Anope::string &name)
Definition: regchannel.cpp:630
int16_t bantype
Definition: regchannel.h:75
NickCore * GetFounder() const
Definition: regchannel.cpp:364
CommandCSInfo(Module *creator)
Definition: cs_info.cpp:17
time_t last_used
Definition: regchannel.h:67
Anope::string display
Definition: account.h:113
#define anope_override
Definition: services.h:56
bool empty() const
Definition: anope.h:126
CSInfo(const Anope::string &modname, const Anope::string &creator)
Definition: cs_info.cpp:91
#define MODULE_INIT(x)
Definition: modules.h:45
bool AllowUnregistered() const
Definition: command.cpp:159
void SetSyntax(const Anope::string &s)
Definition: command.cpp:140
#define CHAN_INFO_HEADER
Definition: language.h:109
Anope::string stringify(const T &x)
Definition: anope.h:710
#define CHAN_X_NOT_REGISTERED
Definition: language.h:84
void SendSyntax(CommandSource &)
Definition: command.cpp:145
const char * c_str() const
Definition: anope.h:117
CommandCSInfo commandcsinfo
Definition: cs_info.cpp:88
CoreExport Anope::string strftime(time_t t, const NickCore *nc=NULL, bool short_output=false)
Definition: misc.cpp:356
#define _(x)
Definition: services.h:50
void Execute(CommandSource &source, const std::vector< Anope::string > &params) anope_override
Definition: cs_info.cpp:24
time_t time_registered
Definition: regchannel.h:66