From fd307e58c27bd10d8e6dc971e55bf08a8f62b4f2 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Tue, 18 Aug 2020 18:38:28 +0200 Subject: [PATCH] Add global-chat shout command Add command to broadcast a message to all instances from clusterctl. --- plugins/global_chat/control.js | 28 ++++++++++++++++++++++++++++ plugins/global_chat/info.js | 3 ++- 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 plugins/global_chat/control.js diff --git a/plugins/global_chat/control.js b/plugins/global_chat/control.js new file mode 100644 index 00000000..acba4340 --- /dev/null +++ b/plugins/global_chat/control.js @@ -0,0 +1,28 @@ +"use strict"; +const plugin = require("lib/plugin"); +const info = require("./info"); +const command = require("lib/command"); + + +const globalChatCommands = new command.CommandTree({ name: "global-chat", description: "Global Chat plugin commands" }); +globalChatCommands.add(new command.Command({ + definition: ["shout ", "Send message to all instances", (yargs) => { + yargs.positional("message", { describe: "message to send", type: "string" }); + }], + handler: async function(args, control) { + await info.messages.chat.send(control, { + instance_name: "Console", + content: args.message, + }); + }, +})); + +class ControlPlugin extends plugin.BaseControlPlugin { + async addCommands(rootCommand) { + rootCommand.add(globalChatCommands); + } +} + +module.exports = { + ControlPlugin, +}; diff --git a/plugins/global_chat/info.js b/plugins/global_chat/info.js index 69764974..7231ce8d 100644 --- a/plugins/global_chat/info.js +++ b/plugins/global_chat/info.js @@ -8,11 +8,12 @@ module.exports = { description: "Forwards chat between instances.", version: "2.0.0-alpha", instanceEntrypoint: "instance", + controlEntrypoint: "control", messages: { chat: new link.Event({ type: "global_chat:chat", - links: ["instance-slave", "slave-master", "master-slave", "slave-instance"], + links: ["instance-slave", "slave-master", "master-slave", "slave-instance", "control-master"], forwardTo: "master", broadcastTo: "instance", eventProperties: {