standard lint
This commit is contained in:
parent
3869e91ed2
commit
cc78b2d7af
|
@ -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.")
|
||||
},
|
||||
};
|
||||
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.')
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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/')
|
||||
},
|
||||
};
|
||||
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/')
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
},
|
||||
};
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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`)
|
||||
}
|
||||
},
|
||||
};
|
||||
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`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
67
index.js
67
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')
|
||||
})
|
||||
console.log(event)
|
||||
bot.join('#bots')
|
||||
bot.join('#cactus')
|
||||
bot.join('#cactus-spam')
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue