From b812b45d86f4f96dac774ced82343a8e691fc051 Mon Sep 17 00:00:00 2001 From: Santiago Forero Date: Thu, 16 Sep 2021 11:33:38 -0500 Subject: [PATCH] implement working grow command --- commands/grow.js | 23 +++++++++++++---------- commands/profile.js | 9 +++++---- index.js | 4 ++-- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/commands/grow.js b/commands/grow.js index 70493fa..080fdf4 100644 --- a/commands/grow.js +++ b/commands/grow.js @@ -4,20 +4,23 @@ module.exports = { name: 'grow', description: 'Grow your cactus.', execute(event, args, bot) { - if(db.get(event.nick + '_cooldown')) { - return bot.say(event.target, "No plant can grow this fast...") + + let grow_rate = Math.random() * (db.get(event.nick + '_score') / 10) + grow_rate = parseFloat(grow_rate.toFixed(3)) + + if(grow_rate == 0) { + grow_rate = 0.1 } - if(db.get(event.nick + '_score') == null) db.set(event.nick + '_score', 1.00) - db.set(event.nick + '_cooldown', true) + if(db.get(event.nick + '_score') == null) { + db.set(event.nick + '_score', 1.000) + } + + db.set(event.nick + '_score', parseFloat(db.get(event.nick + '_score') + parseFloat(grow_rate.toFixed(3)))) + - const grow_rate = parseFloat((Math.random() * (db.get(event.nick + '_score') / 10)).toFixed(2)); - db.add(event.nick + '_score', grow_rate) bot.say(event.target, "You grew " + grow_rate + " cm") - bot.say(event.target, "You are now " + db.get(event.nick + '_score') + " cm") - - setTimeout(() => db.set(event.nick + '_cooldown', false), 0); - + bot.say(event.target, "You are now " + db.get(event.nick + '_score').toFixed(3) + " cm") }, }; \ No newline at end of file diff --git a/commands/profile.js b/commands/profile.js index 4e83863..8839682 100644 --- a/commands/profile.js +++ b/commands/profile.js @@ -7,9 +7,10 @@ module.exports = { user = args[0] || event.nick; bot.say(event.target, user + "'s profile") - if(db.get(user + '_score') == null) db.set(user + '_score', 0) - - bot.say(event.target, 'Current height: ' + db.get(user + '_score') + ' cm') - + if(db.get(user + '_score') == null) { + bot.say(event.target, 'Current height: 0 cm') + } else { + bot.say(event.target, 'Current height: ' + db.get(user + '_score').toFixed(3) + ' cm') + } }, }; \ No newline at end of file diff --git a/index.js b/index.js index 4660be7..a76af13 100644 --- a/index.js +++ b/index.js @@ -6,11 +6,11 @@ var bot = new IRC.Client(); bot.connect({ host: 'irc.tilde.chat', port: 6697, - nick: 'Cactus', + nick: 'CactusBeta', tls: true }); -const prefix = "=" +const prefix = "-" bot.commands = new Map();