diff --git a/bot.js b/bot.js index 3bd4d32..d63a11d 100644 --- a/bot.js +++ b/bot.js @@ -17,7 +17,7 @@ let defaultConfig = { word: "butt", chance: 20, pity: 0, - currentPity: 0, + cooldown: 0, limit: 10, syllableCount: 2, ignoredUsers: [] @@ -25,6 +25,7 @@ let defaultConfig = { let messageCounter = JSON.parse(fs.readFileSync('counter')); let pityTracker = {}; +let cooldownTracker = {}; // Client client.on('message', onMessageHandler); @@ -184,6 +185,16 @@ function onMessageHandler (channel, userstate, message, self) { } else { client.say(channel, "Expected a number, got " + value); } + break; + case "cooldown": + if (isNumeric(value)) { + config.cooldown = parseInt(value); + configurations[channel] = config; + fs.writeFileSync('buttsbot.config', JSON.stringify(configurations)); + client.say(channel, "Set cooldown to " + value + " seconds"); + } else { + client.say(channel, "Expected a number, got " + value); + } default: client.say(channel, "Action '" + action + "' not recognized."); } @@ -191,6 +202,13 @@ function onMessageHandler (channel, userstate, message, self) { console.log(`* buttsbot: User not authorized`); } } else { + let currentTime = Math.floor(new Date().getTime()/1000.0); + + if (cooldownTracker[channel] && config.cooldown > 0) { + if (currentTime - cooldownTracker[channel] < config.cooldown) + return; + } + // ignore commands if (message.startsWith("!")) return; @@ -283,6 +301,7 @@ function onMessageHandler (channel, userstate, message, self) { }); client.say(channel, newMessage.trim()); + if (config.cooldown > 0) cooldownTracker[channel] = currentTime; } console.log(channel + ": " + JSON.stringify(counter));