Anope IRC Services  Version 2.0
ms_ignore.cpp
Go to the documentation of this file.
1 /* MemoServ 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 CommandMSIgnore : public Command
15 {
16  public:
17  CommandMSIgnore(Module *creator) : Command(creator, "memoserv/ignore", 1, 3)
18  {
19  this->SetDesc(_("Manage the memo ignore list"));
20  this->SetSyntax(_("[\037channel\037] ADD \037entry\037"));
21  this->SetSyntax(_("[\037channel\037] DEL \037entry\037"));
22  this->SetSyntax(_("[\037channel\037] LIST"));
23  }
24 
25  void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
26  {
27  if (Anope::ReadOnly)
28  {
29  source.Reply(READ_ONLY_MODE);
30  return;
31  }
32 
33  Anope::string channel = params[0];
34  Anope::string command = (params.size() > 1 ? params[1] : "");
35  Anope::string param = (params.size() > 2 ? params[2] : "");
36 
37  if (channel[0] != '#')
38  {
39  param = command;
40  command = channel;
41  channel = source.GetNick();
42  }
43 
44  bool ischan;
45  MemoInfo *mi = MemoInfo::GetMemoInfo(channel, ischan);
46  ChannelInfo *ci = ChannelInfo::Find(channel);
47  if (!mi)
48  source.Reply(ischan ? CHAN_X_NOT_REGISTERED : _(NICK_X_NOT_REGISTERED), channel.c_str());
49  else if (ischan && !source.AccessFor(ci).HasPriv("MEMO"))
50  source.Reply(ACCESS_DENIED);
51  else if (command.equals_ci("ADD") && !param.empty())
52  {
53  if (std::find(mi->ignores.begin(), mi->ignores.end(), param.ci_str()) == mi->ignores.end())
54  {
55  mi->ignores.push_back(param.ci_str());
56  source.Reply(_("\002%s\002 added to ignore list."), param.c_str());
57  }
58  else
59  source.Reply(_("\002%s\002 is already on the ignore list."), param.c_str());
60  }
61  else if (command.equals_ci("DEL") && !param.empty())
62  {
63  std::vector<Anope::string>::iterator it = std::find(mi->ignores.begin(), mi->ignores.end(), param.ci_str());
64 
65  if (it != mi->ignores.end())
66  {
67  mi->ignores.erase(it);
68  source.Reply(_("\002%s\002 removed from the ignore list."), param.c_str());
69  }
70  else
71  source.Reply(_("\002%s\002 is not on the ignore list."), param.c_str());
72  }
73  else if (command.equals_ci("LIST"))
74  {
75  if (mi->ignores.empty())
76  source.Reply(_("Memo ignore list is empty."));
77  else
78  {
79  ListFormatter list(source.GetAccount());
80  list.AddColumn(_("Mask"));
81  for (unsigned i = 0; i < mi->ignores.size(); ++i)
82  {
84  entry["Mask"] = mi->ignores[i];
85  list.AddEntry(entry);
86  }
87 
88  source.Reply(_("Ignore list:"));
89 
90  std::vector<Anope::string> replies;
91  list.Process(replies);
92 
93  for (unsigned i = 0; i < replies.size(); ++i)
94  source.Reply(replies[i]);
95  }
96  }
97  else
98  this->OnSyntaxError(source, "");
99 
100  return;
101  }
102 
103  bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
104  {
105  this->SendSyntax(source);
106  source.Reply(" ");
107  source.Reply(_("Allows you to ignore users by nick or host from memoing\n"
108  "you or a channel. If someone on the memo ignore list tries\n"
109  "to memo you or a channel, they will not be told that you have\n"
110  "them ignored."));
111  return true;
112  }
113 };
114 
115 class MSIgnore : public Module
116 {
118 
119  public:
120  MSIgnore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
121  commandmsignore(this)
122  {
123  }
124 };
125 
MSIgnore(const Anope::string &modname, const Anope::string &creator)
Definition: ms_ignore.cpp:120
CoreExport bool ReadOnly
Definition: main.cpp:28
Definition: hashcomp.h:84
#define ACCESS_DENIED
Definition: language.h:73
CommandMSIgnore commandmsignore
Definition: ms_ignore.cpp:117
#define NICK_X_NOT_REGISTERED
Definition: language.h:79
static MemoInfo * GetMemoInfo(const Anope::string &targ, bool &is_chan)
Definition: memos.cpp:114
#define READ_ONLY_MODE
Definition: language.h:71
void SetDesc(const Anope::string &d)
Definition: command.cpp:130
bool equals_ci(const char *_str) const
Definition: anope.h:78
static ChannelInfo * Find(const Anope::string &name)
Definition: regchannel.cpp:630
std::map< Anope::string, Anope::string > ListEntry
Definition: lists.h:68
virtual void OnSyntaxError(CommandSource &source, const Anope::string &subcommand)
Definition: command.cpp:191
Definition: memo.h:40
std::vector< Anope::string > ignores
Definition: memo.h:44
bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
Definition: ms_ignore.cpp:103
#define anope_override
Definition: services.h:56
bool empty() const
Definition: anope.h:126
ci::string ci_str() const
Definition: anope.h:121
#define MODULE_INIT(x)
Definition: modules.h:45
void SetSyntax(const Anope::string &s)
Definition: command.cpp:140
#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
CommandMSIgnore(Module *creator)
Definition: ms_ignore.cpp:17
void Execute(CommandSource &source, const std::vector< Anope::string > &params) anope_override
Definition: ms_ignore.cpp:25
#define _(x)
Definition: services.h:50
ListFormatter & AddColumn(const Anope::string &name)
Definition: misc.cpp:128