anope

- supernets anope source code & configuration
git clone git://git.acid.vegas/anope.git
Log | Files | Refs | Archive | README

bs_control.cpp (3495B)

      1 /* BotServ core functions
      2  *
      3  * (C) 2003-2022 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 CommandBSSay : public Command
     15 {
     16  public:
     17 	CommandBSSay(Module *creator) : Command(creator, "botserv/say", 2, 2)
     18 	{
     19 		this->SetDesc(_("Makes the bot say the specified text on the specified channel"));
     20 		this->SetSyntax(_("\037channel\037 \037text\037"));
     21 	}
     22 
     23 	void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
     24 	{
     25 		const Anope::string &text = params[1];
     26 
     27 		ChannelInfo *ci = ChannelInfo::Find(params[0]);
     28 		if (ci == NULL)
     29 		{
     30 			source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str());
     31 			return;
     32 		}
     33 
     34 		if (!source.AccessFor(ci).HasPriv("SAY") && !source.HasPriv("botserv/administration"))
     35 		{
     36 			source.Reply(ACCESS_DENIED);
     37 			return;
     38 		}
     39 
     40 		if (!ci->bi)
     41 		{
     42 			source.Reply(BOT_NOT_ASSIGNED);
     43 			return;
     44 		}
     45 
     46 		if (!ci->c || !ci->c->FindUser(ci->bi))
     47 		{
     48 			source.Reply(BOT_NOT_ON_CHANNEL, ci->name.c_str());
     49 			return;
     50 		}
     51 
     52 		if (text[0] == '\001')
     53 		{
     54 			this->OnSyntaxError(source, "");
     55 			return;
     56 		}
     57 
     58 		IRCD->SendPrivmsg(*ci->bi, ci->name, "%s", text.c_str());
     59 		ci->bi->lastmsg = Anope::CurTime;
     60 
     61 		bool override = !source.AccessFor(ci).HasPriv("SAY");
     62 		Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to say: " << text;
     63 	}
     64 
     65 	bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
     66 	{
     67 		this->SendSyntax(source);
     68 		source.Reply(" ");
     69 		source.Reply(_("Makes the bot say the specified text on the specified channel."));
     70 		return true;
     71 	}
     72 };
     73 
     74 class CommandBSAct : public Command
     75 {
     76  public:
     77 	CommandBSAct(Module *creator) : Command(creator, "botserv/act", 2, 2)
     78 	{
     79 		this->SetDesc(_("Makes the bot do the equivalent of a \"/me\" command"));
     80 		this->SetSyntax(_("\037channel\037 \037text\037"));
     81 	}
     82 
     83 	void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
     84 	{
     85 		Anope::string message = params[1];
     86 
     87 		ChannelInfo *ci = ChannelInfo::Find(params[0]);
     88 		if (ci == NULL)
     89 		{
     90 			source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str());
     91 			return;
     92 		}
     93 
     94 		if (!source.AccessFor(ci).HasPriv("SAY") && !source.HasPriv("botserv/administration"))
     95 		{
     96 			source.Reply(ACCESS_DENIED);
     97 			return;
     98 		}
     99 
    100 		if (!ci->bi)
    101 		{
    102 			source.Reply(BOT_NOT_ASSIGNED);
    103 			return;
    104 		}
    105 
    106 		if (!ci->c || !ci->c->FindUser(ci->bi))
    107 		{
    108 			source.Reply(BOT_NOT_ON_CHANNEL, ci->name.c_str());
    109 			return;
    110 		}
    111 
    112 		message = message.replace_all_cs("\1", "");
    113 		if (message.empty())
    114 			return;
    115 
    116 		IRCD->SendAction(*ci->bi, ci->name, "%s", message.c_str());
    117 		ci->bi->lastmsg = Anope::CurTime;
    118 
    119 		bool override = !source.AccessFor(ci).HasPriv("SAY");
    120 		Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to say: " << message;
    121 	}
    122 
    123 	bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
    124 	{
    125 		this->SendSyntax(source);
    126 		source.Reply(" ");
    127 		source.Reply(_("Makes the bot do the equivalent of a \"/me\" command\n"
    128 				"on the specified channel using the specified text."));
    129 		return true;
    130 	}
    131 };
    132 
    133 class BSControl : public Module
    134 {
    135 	CommandBSSay commandbssay;
    136 	CommandBSAct commandbsact;
    137 
    138  public:
    139 	BSControl(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
    140 		commandbssay(this), commandbsact(this)
    141 	{
    142 
    143 	}
    144 };
    145 
    146 MODULE_INIT(BSControl)