From 483a77930f269bd8716c43761cbdfe4f493dff88 Mon Sep 17 00:00:00 2001 From: hgw Date: Mon, 2 Oct 2023 02:11:26 +0000 Subject: [PATCH] add message listener timeout --- bot.js | 38 +++++++++++++++++++++++++++---------- config/example.default.json | 11 ++++++++++- 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/bot.js b/bot.js index 136314f..a6acb2b 100644 --- a/bot.js +++ b/bot.js @@ -9,7 +9,6 @@ const { Worker } = require('worker_threads'); warningMsg = ''+config.colours.brackets+'['+config.colours.warning+'WARNING'+config.colours.brackets+']' errorMsg = ''+config.colours.brackets+'['+config.colours.error+'ERROR'+config.colours.brackets+']' - var bot = new irc.Client(config.irc.server, config.irc.nickname, { channels: config.irc.channels, secure: config.irc.ssl, @@ -21,6 +20,9 @@ var bot = new irc.Client(config.irc.server, config.irc.nickname, { floodProtectionDelay: config.irc.floodprotectiondelay }); +const msgTimeout = new Set(); +const msgTimeoutMsg = new Set(); + const timer = ms => new Promise(res => setTimeout(res, ms)) const isValidUrl = urlString=> { @@ -111,15 +113,31 @@ async function twitter(chan, provfeed, n) { } bot.addListener('message', function(nick, to, text, from) { - var args = text.split(' '); - if (args[0] === config.irc.prefix+'help') { - help(to, args[1]); - } else if (args[0] === config.irc.prefix+'feed') { - feed(to, nick, args[1], args[2]); - } else if (args[0] === config.irc.prefix+'twitter') { - twitter(to, args[1], args[2]) - } else if (args[0] === config.irc.prefix+'opt') { - opt(to, nick, args[1], args[2], args[3], args[4]) + if (msgTimeout.has(to)) { + if (msgTimeoutMsg.has("yes")) { + return; + } else { + bot.say(to, errorMsg+" You are sending commands too quickly") + msgTimeoutMsg.add("yes"); + setTimeout(() => { + msgTimeoutMsg.delete("yes"); + }, config.misc.command_listen_timeout) + } + } else { + var args = text.split(' '); + if (args[0] === config.irc.prefix+'help') { + help(to, args[1]); + } else if (args[0] === config.irc.prefix+'feed') { + feed(to, nick, args[1], args[2]); + } else if (args[0] === config.irc.prefix+'twitter') { + twitter(to, args[1], args[2]) + } else if (args[0] === config.irc.prefix+'opt') { + opt(to, nick, args[1], args[2], args[3], args[4]) + } + msgTimeout.add(to); + setTimeout(() => { + msgTimeout.delete(to); + }, config.misc.command_listen_timeout) } }); diff --git a/config/example.default.json b/config/example.default.json index 4f6bd62..feeeff4 100644 --- a/config/example.default.json +++ b/config/example.default.json @@ -27,6 +27,7 @@ "body": "00", "link": "02", "help_logo": "07", + "help_motd": "08", "warning": "08", "error": "05" }, @@ -47,6 +48,14 @@ }, "misc": { "display_help_logo": "true", - "logging": "true" + "logging": "true", + "command_listen_timeout": "2500" + }, + "motd": { + "enable": "true", + "list": [ + "COLD HARD CHATS" + ], + "version": "git-master" } } \ No newline at end of file