bs_control.cpp

Go to the documentation of this file.
00001 /* BotServ 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 CommandBSSay : public Command
00017 {
00018  public:
00019         CommandBSSay(Module *creator) : Command(creator, "botserv/say", 2, 2)
00020         {
00021                 this->SetDesc(_("Makes the bot say the given text on the given channel"));
00022                 this->SetSyntax(_("\037channel\037 \037text\037"));
00023         }
00024 
00025         void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
00026         {
00027                 const Anope::string &text = params[1];
00028 
00029                 ChannelInfo *ci = ChannelInfo::Find(params[0]);
00030                 if (ci == NULL)
00031                 {
00032                         source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str());
00033                         return;
00034                 }
00035 
00036                 if (!source.AccessFor(ci).HasPriv("SAY") && !source.HasPriv("botserv/administration"))
00037                 {
00038                         source.Reply(ACCESS_DENIED);
00039                         return;
00040                 }
00041 
00042                 if (!ci->bi)
00043                 {
00044                         source.Reply(BOT_NOT_ASSIGNED);
00045                         return;
00046                 }
00047 
00048                 if (!ci->c || !ci->c->FindUser(ci->bi))
00049                 {
00050                         source.Reply(BOT_NOT_ON_CHANNEL, ci->name.c_str());
00051                         return;
00052                 }
00053 
00054                 if (text[0] == '\001')
00055                 {
00056                         this->OnSyntaxError(source, "");
00057                         return;
00058                 }
00059 
00060                 IRCD->SendPrivmsg(ci->bi, ci->name, "%s", text.c_str());
00061                 ci->bi->lastmsg = Anope::CurTime;
00062 
00063                 bool override = !source.AccessFor(ci).HasPriv("SAY");
00064                 Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to say: " << text;
00065         }
00066 
00067         bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
00068         {
00069                 this->SendSyntax(source);
00070                 source.Reply(" ");
00071                 source.Reply(_("Makes the bot say the given text on the given channel."));
00072                 return true;
00073         }
00074 };
00075 
00076 class CommandBSAct : public Command
00077 {
00078  public:
00079         CommandBSAct(Module *creator) : Command(creator, "botserv/act", 2, 2)
00080         {
00081                 this->SetDesc(_("Makes the bot do the equivalent of a \"/me\" command"));
00082                 this->SetSyntax(_("\037channel\037 \037text\037"));
00083         }
00084 
00085         void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
00086         {
00087                 Anope::string message = params[1];
00088 
00089                 ChannelInfo *ci = ChannelInfo::Find(params[0]);
00090                 if (ci == NULL)
00091                 {
00092                         source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str());
00093                         return;
00094                 }
00095 
00096                 if (!source.AccessFor(ci).HasPriv("SAY") && !source.HasPriv("botserv/administration"))
00097                 {
00098                         source.Reply(ACCESS_DENIED);
00099                         return;
00100                 }
00101 
00102                 if (!ci->bi)
00103                 {
00104                         source.Reply(BOT_NOT_ASSIGNED);
00105                         return;
00106                 }
00107 
00108                 if (!ci->c || !ci->c->FindUser(ci->bi))
00109                 {
00110                         source.Reply(BOT_NOT_ON_CHANNEL, ci->name.c_str());
00111                         return;
00112                 }
00113 
00114                 message = message.replace_all_cs("\1", "");
00115                 if (message.empty())
00116                         return;
00117 
00118                 IRCD->SendAction(ci->bi, ci->name, "%s", message.c_str());
00119                 ci->bi->lastmsg = Anope::CurTime;
00120 
00121                 bool override = !source.AccessFor(ci).HasPriv("SAY");
00122                 Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to say: " << message;
00123         }
00124 
00125         bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
00126         {
00127                 this->SendSyntax(source);
00128                 source.Reply(" ");
00129                 source.Reply(_("Makes the bot do the equivalent of a \"/me\" command\n"
00130                                 "on the given channel using the given text."));
00131                 return true;
00132         }
00133 };
00134 
00135 class BSControl : public Module
00136 {
00137         CommandBSSay commandbssay;
00138         CommandBSAct commandbsact;
00139 
00140  public:
00141         BSControl(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE),
00142                 commandbssay(this), commandbsact(this)
00143         {
00144                 this->SetAuthor("Anope");
00145 
00146         }
00147 };
00148 
00149 MODULE_INIT(BSControl)