From cc78b2d7af1279bf7d56438350d542d68177911a Mon Sep 17 00:00:00 2001 From: Santiago Forero Date: Thu, 16 Sep 2021 16:41:40 -0500 Subject: [PATCH] standard lint --- commands/grow.js | 32 ++++++++++---------- commands/help.js | 24 +++++++-------- commands/leaderboard.js | 45 +++++++++++++-------------- commands/profile.js | 22 +++++++------- index.js | 67 ++++++++++++++++++++--------------------- 5 files changed, 95 insertions(+), 95 deletions(-) diff --git a/commands/grow.js b/commands/grow.js index 91d6dcd..0c688ae 100644 --- a/commands/grow.js +++ b/commands/grow.js @@ -1,19 +1,19 @@ const db = require('quick.db') module.exports = { - name: 'grow', - description: 'Grow your cactus.', - execute(event, args, bot) { - 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.000) - } - - db.set(event.nick + '_score', parseFloat(db.get(event.nick + '_score') + parseFloat(grow_rate.toFixed(3)))) - bot.say(event.target, event.nick + ": You grew " + grow_rate + " cm, you are now " + db.get(event.nick + '_score').toFixed(3) + " cm.") - }, -}; \ No newline at end of file + name: 'grow', + description: 'Grow your cactus.', + execute (event, args, bot) { + let growRate = Math.random() * (db.get(event.nick + '_score') / 10) + growRate = parseFloat(growRate.toFixed(3)) + if (growRate === 0) { + growRate = 0.1 + } + 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(growRate.toFixed(3)))) + bot.say(event.target, event.nick + ': You grew ' + growRate + ' cm, you are now ' + db.get(event.nick + '_score').toFixed(3) + ' cm.') + } +} diff --git a/commands/help.js b/commands/help.js index 85d5cb2..5ec819e 100644 --- a/commands/help.js +++ b/commands/help.js @@ -1,13 +1,13 @@ module.exports = { - name: 'help', - description: 'Get info and help about this bot.', - execute(event, args, bot) { - text = "" - bot.commands.forEach((value, key, map) => { - text += value.name + ": " + value.description + ' | ' - }) - - bot.say(event.target, 'Hi, I\'m Cactus, you can grow a cactus to become the tallest! My maintainer is forero, my prefix is \'=\' and my commands are:') - bot.say(event.target, text + 'Source: https://tildegit.org/forero/cactus-irc/') - }, -}; \ No newline at end of file + name: 'help', + description: 'Get info and help about this bot.', + execute (event, args, bot) { + let text + bot.commands.forEach((value, key, map) => { + text += value.name + ': ' + value.description + ' | ' + }) + + bot.say(event.target, 'Hi, I\'m Cactus, you can grow a cactus to become the tallest! My maintainer is forero, my prefix is \'=\' and my commands are:') + bot.say(event.target, text + 'Source: https://tildegit.org/forero/cactus-irc/') + } +} diff --git a/commands/leaderboard.js b/commands/leaderboard.js index 93fa5d2..0170bfd 100644 --- a/commands/leaderboard.js +++ b/commands/leaderboard.js @@ -1,27 +1,28 @@ const db = require('quick.db') module.exports = { - name: 'leaderboard', - description: 'List of tallests cactuses.', - execute(event, args, bot) { - data = db.all() - data.map(score => { - score.ID = score.ID.replace('_score','') - score.data = parseFloat(parseFloat(score.data).toFixed(3)) - }) - - data.sort(function (a, b) { - return b.data - a.data - }); + name: 'leaderboard', + description: 'List of tallests cactuses.', + execute (event, args, bot) { + const data = db.all() + data.map(score => { + score.ID = score.ID.replace('_score', '') + score.data = parseFloat(parseFloat(score.data).toFixed(3)) + return 0 + }) - console.log(data) + data.sort(function (a, b) { + return b.data - a.data + }) - let text = "" - for(let i = 0; i < 5; i++) { - if(data[i] != undefined) { - text += `${i + 1}. ${data[i].ID} (${data[i].data} cm) ` - } - } + console.log(data) - bot.say(event.target, 'Cactus Leaderboard: ' + text) - }, -}; \ No newline at end of file + let text = '' + for (let i = 0; i < 5; i++) { + if (data[i] !== undefined) { + text += `${i + 1}. ${data[i].ID} (${data[i].data} cm) ` + } + } + + bot.say(event.target, 'Cactus Leaderboard: ' + text) + } +} diff --git a/commands/profile.js b/commands/profile.js index 7f1752f..b6b931d 100644 --- a/commands/profile.js +++ b/commands/profile.js @@ -1,14 +1,14 @@ const db = require('quick.db') module.exports = { - name: 'profile', - description: 'See your profile or someone else\'s profile.', - execute(event, args, bot) { - user = args[0] || event.nick; - if(db.get(user + '_score') == null) { - bot.say(event.target, `${user}'s profile: Current height: 0 cm`) - } else { - bot.say(event.target, `${user}'s profile: Current height: ${db.get(user + '_score').toFixed(3)} cm`) - } - }, -}; \ No newline at end of file + name: 'profile', + description: 'See your profile or someone else\'s profile.', + execute (event, args, bot) { + const user = args[0] || event.nick + if (db.get(user + '_score') == null) { + bot.say(event.target, `${user}'s profile: Current height: 0 cm`) + } else { + bot.say(event.target, `${user}'s profile: Current height: ${db.get(user + '_score').toFixed(3)} cm`) + } + } +} diff --git a/index.js b/index.js index 42ab784..6ee71c8 100644 --- a/index.js +++ b/index.js @@ -1,52 +1,51 @@ -const IRC = require('irc-framework'); -const fs = require('fs'); +const IRC = require('irc-framework') +const fs = require('fs') -var bot = new IRC.Client(); +const bot = new IRC.Client() bot.connect({ - host: 'irc.tilde.chat', - port: 6697, - nick: 'Cactus', - tls: true -}); + host: 'irc.tilde.chat', + port: 6697, + nick: 'Cactus', + tls: true +}) -const prefix = "=" +const prefix = '=' -bot.commands = new Map(); +bot.commands = new Map() -const commandFiles = fs.readdirSync(`./commands`).filter(file => file.endsWith('.js')); +const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js')) for (const file of commandFiles) { - const command = require(`./commands/${file}`); - - bot.commands.set(command.name, command); + const command = require(`./commands/${file}`) + + bot.commands.set(command.name, command) } bot.on('message', event => { - const args = event.message.slice(prefix.length).trim().split(/ +/); - if(event.message == '!botlist') { - - bot.say(event.target, `Hello, I'm Cactus, my maintainer is forero and my prefix is '${prefix}'. For more information type: ${prefix}help, join #cactus for help`); - } + const args = event.message.slice(prefix.length).trim().split(/ +/) + if (event.message === '!botlist') { + bot.say(event.target, `Hello, I'm Cactus, my maintainer is forero and my prefix is '${prefix}'. For more information type: ${prefix}help, join #cactus for help`) + } - if (!event.message.startsWith(prefix)) return; - const commandName = args.shift().toLowerCase(); + if (!event.message.startsWith(prefix)) return + const commandName = args.shift().toLowerCase() - const command = bot.commands.get(commandName) + const command = bot.commands.get(commandName) - if (!command) return; + if (!command) return - try { - command.execute(event, args, bot); - } catch (error) { - console.error(error); - bot.say(event.target, 'there was an error trying to execute that command!'); - } + try { + command.execute(event, args, bot) + } catch (error) { + console.error(error) + bot.say(event.target, 'there was an error trying to execute that command!') + } }) bot.on('registered', event => { - console.log(event) - bot.join('#bots') - bot.join('#cactus') - bot.join('#cactus-spam') -}) \ No newline at end of file + console.log(event) + bot.join('#bots') + bot.join('#cactus') + bot.join('#cactus-spam') +})