mirror of
https://github.com/anope/anope.git
synced 2026-06-29 11:56:38 +02:00
Rework sending global notices.
Admins can now queue multiple messages and send them when they are ready. This is fully compatible with the previous global behaviour. Admins can now also send messages to individual servers. This is useful for informing users of maintenance due to downtime.
This commit is contained in:
@@ -14,40 +14,75 @@
|
||||
class CommandGLGlobal final
|
||||
: public Command
|
||||
{
|
||||
ServiceReference<GlobalService> GService;
|
||||
private:
|
||||
ServiceReference<GlobalService> global;
|
||||
|
||||
BotInfo *GetSender(CommandSource &source)
|
||||
{
|
||||
Reference<BotInfo> sender;
|
||||
if (global)
|
||||
sender = global->GetDefaultSender();
|
||||
if (!sender)
|
||||
sender = source.service;
|
||||
return sender;
|
||||
}
|
||||
|
||||
public:
|
||||
CommandGLGlobal(Module *creator) : Command(creator, "global/global", 1, 1), GService("GlobalService", "Global")
|
||||
CommandGLGlobal(Module *creator)
|
||||
: Command(creator, "global/global", 0)
|
||||
, global("GlobalService", "Global")
|
||||
{
|
||||
this->SetDesc(_("Send a message to all users"));
|
||||
this->SetSyntax(_("\037message\037"));
|
||||
this->SetSyntax(_("[\037message\037]"));
|
||||
}
|
||||
|
||||
void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override
|
||||
{
|
||||
const Anope::string &msg = params[0];
|
||||
if (!global)
|
||||
{
|
||||
source.Reply(SERVICE_UNAVAILABLE, source.service->nick.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
if (!GService)
|
||||
source.Reply("No global reference, is global loaded?");
|
||||
auto queuesize = global->CountQueue(source.nc);
|
||||
if (!queuesize && params.empty())
|
||||
{
|
||||
source.Reply(GLOBAL_NO_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (queuesize && !params.empty())
|
||||
{
|
||||
source.Reply(GLOBAL_QUEUE_CONFLICT);
|
||||
return;
|
||||
}
|
||||
|
||||
if (params.empty())
|
||||
{
|
||||
// We are sending the message queue.
|
||||
global->SendQueue(source, GetSender(source));
|
||||
}
|
||||
else
|
||||
{
|
||||
Log(LOG_ADMIN, source, this);
|
||||
GService->SendGlobal(NULL, source.GetNick(), msg);
|
||||
// We are sending a single message.
|
||||
global->SendSingle(params[0], &source, GetSender(source));
|
||||
queuesize = 1;
|
||||
}
|
||||
|
||||
Log(LOG_ADMIN, source, this) << "to send " << queuesize << " messages to all users";
|
||||
}
|
||||
|
||||
bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
|
||||
{
|
||||
Reference<BotInfo> sender;
|
||||
if (GService)
|
||||
sender = GService->GetDefaultSender();
|
||||
if (!sender)
|
||||
sender = source.service;
|
||||
|
||||
this->SendSyntax(source);
|
||||
source.Reply(" ");
|
||||
source.Reply(_("Allows Administrators to send messages to all users on the\n"
|
||||
"network. The message will be sent from the nick \002%s\002."), sender->nick.c_str());
|
||||
source.Reply(_(
|
||||
"Allows sending messages to all users on the network. The message will be sent\n"
|
||||
"from \002%s\002.\n"
|
||||
"\n"
|
||||
"You can either send a message by specifying it as a parameter or provide no\n"
|
||||
"parameters to send a previously queued message.\n"
|
||||
), GetSender(source)->nick.c_str());
|
||||
return true;
|
||||
}
|
||||
};
|
||||
@@ -55,11 +90,13 @@ public:
|
||||
class GLGlobal final
|
||||
: public Module
|
||||
{
|
||||
private:
|
||||
CommandGLGlobal commandglglobal;
|
||||
|
||||
public:
|
||||
GLGlobal(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
|
||||
commandglglobal(this)
|
||||
GLGlobal(const Anope::string &modname, const Anope::string &creator)
|
||||
: Module(modname, creator, VENDOR)
|
||||
, commandglglobal(this)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user