ns_set_message.cpp

Go to the documentation of this file.
00001 /* NickServ core functions
00002  *
00003  * (C) 2003-2012 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 CommandNSSetMessage : public Command
00017 {
00018  public:
00019         CommandNSSetMessage(Module *creator, const Anope::string &sname = "nickserv/set/message", size_t min = 1) : Command(creator, sname, min, min + 1)
00020         {
00021                 this->SetDesc(_("Change the communication method of Services"));
00022                 this->SetSyntax(_("{ON | OFF}"));
00023         }
00024 
00025         void Run(CommandSource &source, const Anope::string &user, const Anope::string &param)
00026         {
00027                 const NickAlias *na = NickAlias::Find(user);
00028                 if (!na)
00029                 {
00030                         source.Reply(NICK_X_NOT_REGISTERED, user.c_str());
00031                         return;
00032                 }
00033                 NickCore *nc = na->nc;
00034 
00035                 if (!Config->UsePrivmsg)
00036                 {
00037                         source.Reply(_("You cannot %s on this network."), source.command.c_str());
00038                         return;
00039                 }
00040 
00041                 EventReturn MOD_RESULT;
00042                 FOREACH_RESULT(I_OnSetNickOption, OnSetNickOption(source, this, nc, param));
00043                 if (MOD_RESULT == EVENT_STOP)
00044                         return;
00045 
00046                 if (param.equals_ci("ON"))
00047                 {
00048                         nc->SetFlag(NI_MSG);
00049                         source.Reply(_("Services will now reply to \002%s\002 with \002messages\002."), nc->display.c_str());
00050                 }
00051                 else if (param.equals_ci("OFF"))
00052                 {
00053                         nc->UnsetFlag(NI_MSG);
00054                         source.Reply(_("Services will now reply to \002%s\002 with \002notices\002."), nc->display.c_str());
00055                 }
00056                 else
00057                         this->OnSyntaxError(source, "MSG");
00058 
00059                 return;
00060         }
00061 
00062         void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
00063         {
00064                 this->Run(source, source.nc->display, params[0]);
00065         }
00066 
00067         bool OnHelp(CommandSource &source, const Anope::string &) anope_override
00068         {
00069                 this->SendSyntax(source);
00070                 source.Reply(" ");
00071                 source.Reply(_("Allows you to choose the way Services are communicating with \n"
00072                                 "you. With \002MSG\002 set, Services will use messages, else they'll \n"
00073                                 "use notices."));
00074                 return true;
00075         }
00076 
00077         void OnServHelp(CommandSource &source) anope_override
00078         {
00079                 if (Config->UsePrivmsg)
00080                         Command::OnServHelp(source);
00081         }
00082 };
00083 
00084 class CommandNSSASetMessage : public CommandNSSetMessage
00085 {
00086  public:
00087         CommandNSSASetMessage(Module *creator) : CommandNSSetMessage(creator, "nickserv/saset/message", 2)
00088         {
00089                 this->ClearSyntax();
00090                 this->SetSyntax(_("\037nickname\037 {ON | OFF}"));
00091         }
00092 
00093         bool OnHelp(CommandSource &source, const Anope::string &) anope_override
00094         {
00095                 this->SendSyntax(source);
00096                 source.Reply(" ");
00097                 source.Reply(_("Allows you to choose the way Services are communicating with \n"
00098                                 "the given user. With \002MSG\002 set, Services will use messages,\n"
00099                                 "else they'll use notices."));
00100                 return true;
00101         }
00102 
00103         void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
00104         {
00105                 this->Run(source, params[0], params[1]);
00106         }
00107 };
00108 
00109 class NSSetMessage : public Module
00110 {
00111         CommandNSSetMessage commandnssetmessage;
00112         CommandNSSASetMessage commandnssasetmessage;
00113 
00114  public:
00115         NSSetMessage(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE),
00116                 commandnssetmessage(this), commandnssasetmessage(this)
00117         {
00118                 this->SetAuthor("Anope");
00119 
00120         }
00121 };
00122 
00123 MODULE_INIT(NSSetMessage)