standard lint
This commit is contained in:
parent
3869e91ed2
commit
cc78b2d7af
|
@ -1,19 +1,19 @@
|
||||||
const db = require('quick.db')
|
const db = require('quick.db')
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'grow',
|
name: 'grow',
|
||||||
description: 'Grow your cactus.',
|
description: 'Grow your cactus.',
|
||||||
execute(event, args, bot) {
|
execute (event, args, bot) {
|
||||||
let grow_rate = Math.random() * (db.get(event.nick + '_score') / 10)
|
let growRate = Math.random() * (db.get(event.nick + '_score') / 10)
|
||||||
grow_rate = parseFloat(grow_rate.toFixed(3))
|
growRate = parseFloat(growRate.toFixed(3))
|
||||||
if(grow_rate == 0) {
|
if (growRate === 0) {
|
||||||
grow_rate = 0.1
|
growRate = 0.1
|
||||||
}
|
}
|
||||||
if(db.get(event.nick + '_score') == null) {
|
if (db.get(event.nick + '_score') == null) {
|
||||||
db.set(event.nick + '_score', 1.000)
|
db.set(event.nick + '_score', 1.000)
|
||||||
}
|
}
|
||||||
|
|
||||||
db.set(event.nick + '_score', parseFloat(db.get(event.nick + '_score') + parseFloat(grow_rate.toFixed(3))))
|
db.set(event.nick + '_score', parseFloat(db.get(event.nick + '_score') + parseFloat(growRate.toFixed(3))))
|
||||||
bot.say(event.target, event.nick + ": You grew " + grow_rate + " cm, you are now " + db.get(event.nick + '_score').toFixed(3) + " cm.")
|
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 = {
|
module.exports = {
|
||||||
name: 'help',
|
name: 'help',
|
||||||
description: 'Get info and help about this bot.',
|
description: 'Get info and help about this bot.',
|
||||||
execute(event, args, bot) {
|
execute (event, args, bot) {
|
||||||
text = ""
|
let text
|
||||||
bot.commands.forEach((value, key, map) => {
|
bot.commands.forEach((value, key, map) => {
|
||||||
text += value.name + ": " + value.description + ' | '
|
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, '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/')
|
bot.say(event.target, text + 'Source: https://tildegit.org/forero/cactus-irc/')
|
||||||
},
|
}
|
||||||
};
|
}
|
||||||
|
|
|
@ -1,27 +1,28 @@
|
||||||
const db = require('quick.db')
|
const db = require('quick.db')
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'leaderboard',
|
name: 'leaderboard',
|
||||||
description: 'List of tallests cactuses.',
|
description: 'List of tallests cactuses.',
|
||||||
execute(event, args, bot) {
|
execute (event, args, bot) {
|
||||||
data = db.all()
|
const data = db.all()
|
||||||
data.map(score => {
|
data.map(score => {
|
||||||
score.ID = score.ID.replace('_score','')
|
score.ID = score.ID.replace('_score', '')
|
||||||
score.data = parseFloat(parseFloat(score.data).toFixed(3))
|
score.data = parseFloat(parseFloat(score.data).toFixed(3))
|
||||||
})
|
return 0
|
||||||
|
})
|
||||||
data.sort(function (a, b) {
|
|
||||||
return b.data - a.data
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log(data)
|
data.sort(function (a, b) {
|
||||||
|
return b.data - a.data
|
||||||
|
})
|
||||||
|
|
||||||
let text = ""
|
console.log(data)
|
||||||
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)
|
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')
|
const db = require('quick.db')
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'profile',
|
name: 'profile',
|
||||||
description: 'See your profile or someone else\'s profile.',
|
description: 'See your profile or someone else\'s profile.',
|
||||||
execute(event, args, bot) {
|
execute (event, args, bot) {
|
||||||
user = args[0] || event.nick;
|
const user = args[0] || event.nick
|
||||||
if(db.get(user + '_score') == null) {
|
if (db.get(user + '_score') == null) {
|
||||||
bot.say(event.target, `${user}'s profile: Current height: 0 cm`)
|
bot.say(event.target, `${user}'s profile: Current height: 0 cm`)
|
||||||
} else {
|
} else {
|
||||||
bot.say(event.target, `${user}'s profile: Current height: ${db.get(user + '_score').toFixed(3)} cm`)
|
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 IRC = require('irc-framework')
|
||||||
const fs = require('fs');
|
const fs = require('fs')
|
||||||
|
|
||||||
var bot = new IRC.Client();
|
const bot = new IRC.Client()
|
||||||
|
|
||||||
bot.connect({
|
bot.connect({
|
||||||
host: 'irc.tilde.chat',
|
host: 'irc.tilde.chat',
|
||||||
port: 6697,
|
port: 6697,
|
||||||
nick: 'Cactus',
|
nick: 'Cactus',
|
||||||
tls: true
|
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) {
|
for (const file of commandFiles) {
|
||||||
const command = require(`./commands/${file}`);
|
const command = require(`./commands/${file}`)
|
||||||
|
|
||||||
bot.commands.set(command.name, command);
|
bot.commands.set(command.name, command)
|
||||||
}
|
}
|
||||||
|
|
||||||
bot.on('message', event => {
|
bot.on('message', event => {
|
||||||
const args = event.message.slice(prefix.length).trim().split(/ +/);
|
const args = event.message.slice(prefix.length).trim().split(/ +/)
|
||||||
if(event.message == '!botlist') {
|
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`)
|
||||||
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;
|
if (!event.message.startsWith(prefix)) return
|
||||||
const commandName = args.shift().toLowerCase();
|
const commandName = args.shift().toLowerCase()
|
||||||
|
|
||||||
const command = bot.commands.get(commandName)
|
const command = bot.commands.get(commandName)
|
||||||
|
|
||||||
if (!command) return;
|
if (!command) return
|
||||||
|
|
||||||
try {
|
try {
|
||||||
command.execute(event, args, bot);
|
command.execute(event, args, bot)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error)
|
||||||
bot.say(event.target, 'there was an error trying to execute that command!');
|
bot.say(event.target, 'there was an error trying to execute that command!')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
bot.on('registered', event => {
|
bot.on('registered', event => {
|
||||||
console.log(event)
|
console.log(event)
|
||||||
bot.join('#bots')
|
bot.join('#bots')
|
||||||
bot.join('#cactus')
|
bot.join('#cactus')
|
||||||
bot.join('#cactus-spam')
|
bot.join('#cactus-spam')
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue