Added cooldown option
This commit is contained in:
parent
0b3a4f4ad0
commit
938aa28772
21
bot.js
21
bot.js
|
|
@ -17,7 +17,7 @@ let defaultConfig = {
|
||||||
word: "butt",
|
word: "butt",
|
||||||
chance: 20,
|
chance: 20,
|
||||||
pity: 0,
|
pity: 0,
|
||||||
currentPity: 0,
|
cooldown: 0,
|
||||||
limit: 10,
|
limit: 10,
|
||||||
syllableCount: 2,
|
syllableCount: 2,
|
||||||
ignoredUsers: []
|
ignoredUsers: []
|
||||||
|
|
@ -25,6 +25,7 @@ let defaultConfig = {
|
||||||
|
|
||||||
let messageCounter = JSON.parse(fs.readFileSync('counter'));
|
let messageCounter = JSON.parse(fs.readFileSync('counter'));
|
||||||
let pityTracker = {};
|
let pityTracker = {};
|
||||||
|
let cooldownTracker = {};
|
||||||
|
|
||||||
// Client
|
// Client
|
||||||
client.on('message', onMessageHandler);
|
client.on('message', onMessageHandler);
|
||||||
|
|
@ -184,6 +185,16 @@ function onMessageHandler (channel, userstate, message, self) {
|
||||||
} else {
|
} else {
|
||||||
client.say(channel, "Expected a number, got " + value);
|
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:
|
default:
|
||||||
client.say(channel, "Action '" + action + "' not recognized.");
|
client.say(channel, "Action '" + action + "' not recognized.");
|
||||||
}
|
}
|
||||||
|
|
@ -191,6 +202,13 @@ function onMessageHandler (channel, userstate, message, self) {
|
||||||
console.log(`* buttsbot: User not authorized`);
|
console.log(`* buttsbot: User not authorized`);
|
||||||
}
|
}
|
||||||
} else {
|
} 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
|
// ignore commands
|
||||||
if (message.startsWith("!"))
|
if (message.startsWith("!"))
|
||||||
return;
|
return;
|
||||||
|
|
@ -283,6 +301,7 @@ function onMessageHandler (channel, userstate, message, self) {
|
||||||
});
|
});
|
||||||
|
|
||||||
client.say(channel, newMessage.trim());
|
client.say(channel, newMessage.trim());
|
||||||
|
if (config.cooldown > 0) cooldownTracker[channel] = currentTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(channel + ": " + JSON.stringify(counter));
|
console.log(channel + ": " + JSON.stringify(counter));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user