From 5d54d2e3d78bead628ba794d8dcbe2c2f84588fd Mon Sep 17 00:00:00 2001 From: Adhidarma Hadiwinoto <adhisimon@gmail.com> Date: Mon, 20 Dec 2021 15:31:57 +0700 Subject: [PATCH] Add config.custom_ping.add_buddies_on_init --- config.sample.json | 1 + lib/custom-ping.js | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/config.sample.json b/config.sample.json index b9d6fc4..e5f7e1d 100644 --- a/config.sample.json +++ b/config.sample.json @@ -11,6 +11,7 @@ "verbose": false, "disable_pong": false, "allowed_from_all": false, + "add_buddies_on_init": false, "allowed_from_partners": [], "send_to": [] }, diff --git a/lib/custom-ping.js b/lib/custom-ping.js index 704fce2..acfaf52 100644 --- a/lib/custom-ping.js +++ b/lib/custom-ping.js @@ -112,9 +112,32 @@ const pingSender = async () => { pingSender(); }; +const addBuddiesOnInit = () => { + if ( + !config.custom_ping || !config.custom_ping.send_to + || !Array.isArray(config.custom_ping.send_to) + || !config.custom_ping.send_to.length + ) { + return; + } + + logger.verbose(`${MODULE_NAME} 3BBD9A02: Adding custom ping targets as buddies`, { + targets: config.custom_ping.send_to, + }); + + config.custom_ping.send_to.forEach((target) => { + bot.subscribe(target); + }); +}; + const setBot = (botFromCaller) => { logger.verbose(`${MODULE_NAME} A063F39F: Bot registered for custom ping`); bot = botFromCaller; + + if (config.custom_ping && config.custom_ping.add_buddies_on_init) { + addBuddiesOnInit(); + } + pingSender(); }; exports.setBot = setBot; -- 1.9.0