Added pity system

This commit is contained in:
Marco Loewe 2021-09-03 19:43:17 +02:00
parent 0f65dcfdee
commit 39195e2445

18
bot.js
View File

@ -16,6 +16,8 @@ let configurations = JSON.parse(configFile);
let defaultConfig = { let defaultConfig = {
word: "butt", word: "butt",
chance: 20, chance: 20,
pity: 0,
currentPity: 0,
limit: 10, limit: 10,
syllableCount: 2, syllableCount: 2,
ignoredUsers: [] ignoredUsers: []
@ -117,6 +119,16 @@ function onMessageHandler (channel, userstate, message, self) {
client.say(channel, "Expected a number, got " + value); client.say(channel, "Expected a number, got " + value);
} }
break; break;
case "pity":
if (isNumeric(value)) {
config.pity = parseInt(value);
configurations[channel] = config;
fs.writeFileSync('buttsbot.config', JSON.stringify(configurations));
client.say(channel, "Pity set to " + value);
} else {
client.say(channel, "Expected a number, got " + value);
}
break;
case "ignore": case "ignore":
if (value && value !== "") { if (value && value !== "") {
console.log(`* ignore: value ok`); console.log(`* ignore: value ok`);
@ -226,7 +238,9 @@ function onMessageHandler (channel, userstate, message, self) {
// random chance // random chance
// TODO: find a better alternative // TODO: find a better alternative
var number = Math.random() * 100; var number = Math.random() * 100;
if (number <= config.chance) { if (number <= config.chance || config.currentPity == config.pity) {
config.currentPity = 0;
counter.converted++; counter.converted++;
@ -261,6 +275,8 @@ function onMessageHandler (channel, userstate, message, self) {
}); });
client.say(channel, newMessage.trim()); client.say(channel, newMessage.trim());
} else {
config.currentPity++;
} }
console.log(channel + ": " + JSON.stringify(counter)); console.log(channel + ": " + JSON.stringify(counter));