summaryrefslogtreecommitdiff
path: root/modules/global/gl_server.cpp
diff options
context:
space:
mode:
authorSadie Powell <sadie@witchery.services>2024-03-14 21:18:08 +0000
committerSadie Powell <sadie@witchery.services>2024-03-14 21:35:17 +0000
commitbeaf09de7bcb0042dfd8f388064126e511a5b28d (patch)
treeba14e1ff1ff96b5623c459b2de35d766d086e427 /modules/global/gl_server.cpp
parentc8d8978cd0bfb10613da331c5b13bbcf8486f85f (diff)
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.
Diffstat (limited to 'modules/global/gl_server.cpp')
-rw-r--r--modules/global/gl_server.cpp112
1 files changed, 112 insertions, 0 deletions
diff --git a/modules/global/gl_server.cpp b/modules/global/gl_server.cpp
new file mode 100644
index 000000000..d1f1cffe2
--- /dev/null
+++ b/modules/global/gl_server.cpp
@@ -0,0 +1,112 @@
+/* Global core functions
+ *
+ * (C) 2003-2024 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ */
+
+#include "module.h"
+
+class CommandGLServer final
+ : public Command
+{
+private:
+ ServiceReference<GlobalService> global;
+
+ BotInfo *GetSender(CommandSource &source)
+ {
+ Reference<BotInfo> sender;
+ if (global)
+ sender = global->GetDefaultSender();
+ if (!sender)
+ sender = source.service;
+ return sender;
+ }
+
+public:
+ CommandGLServer(Module *creator)
+ : Command(creator, "global/server", 1)
+ , global("GlobalService", "Global")
+ {
+ this->SetDesc(_("Send a message to all users on a server"));
+ this->SetSyntax(_("\037server\037 [\037message\037]"));
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ if (!global)
+ {
+ source.Reply(SERVICE_UNAVAILABLE, source.service->nick.c_str());
+ return;
+ }
+
+ auto *server = Server::Find(params[0]);
+ if (!server || server == Me || server->IsJuped())
+ {
+ source.Reply(_("Server \002%s\002 is not linked to the network."), params[0].c_str());
+ return;
+ }
+
+ auto queuesize = global->CountQueue(source.nc);
+ if (!queuesize && params.size() < 2)
+ {
+ source.Reply(GLOBAL_NO_MESSAGE);
+ return;
+ }
+
+ if (queuesize && params.size() > 1)
+ {
+ source.Reply(GLOBAL_QUEUE_CONFLICT);
+ return;
+ }
+
+ if (params.empty())
+ {
+ // We are sending the message queue.
+ global->SendQueue(source, GetSender(source), server);
+ }
+ else
+ {
+ // We are sending a single message.
+ global->SendSingle(params[1], &source, GetSender(source), server);
+ queuesize = 1;
+ }
+
+ Log(LOG_ADMIN, source, this) << "to send " << queuesize << " messages to users on " << server->GetName();
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
+ {
+ this->SendSyntax(source);
+ source.Reply(" ");
+ source.Reply(_(
+ "Allows sending messages to all users on a server. 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;
+ }
+};
+
+class GLServer final
+ : public Module
+{
+private:
+ CommandGLServer commandglserver;
+
+public:
+ GLServer(const Anope::string &modname, const Anope::string &creator)
+ : Module(modname, creator, VENDOR)
+ , commandglserver(this)
+ {
+
+ }
+};
+
+MODULE_INIT(GLServer)