add message listener timeout

This commit is contained in:
hgw 2023-10-02 02:11:26 +00:00
parent e536d8f22a
commit 483a77930f
2 changed files with 38 additions and 11 deletions

38
bot.js
View File

@ -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)
}
});

View File

@ -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"
}
}