Compare commits

...

2 Commits

Author SHA1 Message Date
Santiago Forero 82879e7587 add basic usable version, delete leaderboard and daily commands, for now 2021-09-08 12:24:01 -05:00
Santiago Forero afd621e6c1 create basic command handler 2021-09-08 10:00:14 -05:00
7 changed files with 2365 additions and 0 deletions

2
.gitignore vendored
View File

@ -118,3 +118,5 @@ dist
.yarn/install-state.gz
.pnp.*
# databases
json.sqlite

20
commands/grow.js Normal file
View File

@ -0,0 +1,20 @@
const db = require('quick.db')
module.exports = {
name: 'grow',
description: 'Grow your cactus.',
execute(event, args, bot) {
if(db.get(event.nick + '_score') == null) db.set(event.nick + '_score', 0)
if(db.get(event.nick + '_hpg') == null) db.set(event.nick + '_hpg', 2)
db.add(event.nick + '_score', db.get(event.nick + '_hpg'))
bot.say(event.target, "You grew " + db.get(event.nick + '_hpg') + " cm")
bot.say(event.target, "You are now " + db.get(event.nick + '_score') + " cm")
},
};

13
commands/help.js Normal file
View File

@ -0,0 +1,13 @@
module.exports = {
name: 'help',
description: 'Get info and help about this bot.',
execute(event, args, bot) {
bot.say(event.target, 'Hi, I\'m Cactus, you can live the life of a cactus and grow to become the tallest! My maintainer is forero, my prefix is \'=\' and my commands are: ')
bot.commands.forEach((value, key, map) => {
bot.say(event.target, value.name + ": " + value.description)
})
bot.say(event.target, 'Source: https://tildegit.org/forero/cactus-irc/')
},
};

20
commands/profile.js Normal file
View File

@ -0,0 +1,20 @@
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;
bot.say(event.target, user + "' profile")
if(db.get(user + '_score') == null) db.set(user + '_score', 0)
if(db.get(user + '_hpg') == null) db.set(user + '_hpg', 2)
bot.say(event.target, 'Current height: ' + db.get(user + '_score') + ' cm')
bot.say(event.target, "Height per growth: " + db.get(user + '_hpg') + " cm")
},
};

73
index.js Normal file
View File

@ -0,0 +1,73 @@
const IRC = require('irc-framework');
const fs = require('fs');
var bot = new IRC.Client();
bot.connect({
host: 'irc.tilde.chat',
port: 6697,
nick: 'Cactus',
tls: true
});
const prefix = "="
bot.commands = new Map();
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);
}
bot.on('message', event => {
const args = event.message.slice(prefix.length).trim().split(/ +/);
if(event.message == '!botlist') {
bot.commands.get('help').execute(event, args, bot);
}
if (!event.message.startsWith(prefix)) return;
const commandName = args.shift().toLowerCase();
const command = bot.commands.get(commandName)
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!');
}
})
bot.on('registered', event => {
console.log(event)
bot.join('#bots')
bot.join('#cactus')
bot.say('NickServ', 'identify 1021513305')
})

2218
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

19
package.json Normal file
View File

@ -0,0 +1,19 @@
{
"name": "cactus-irc",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://tildegit.org/forero/cactus-irc"
},
"author": "Santiago Forero",
"license": "MIT",
"dependencies": {
"irc-framework": "^4.11.0",
"quick.db": "^7.1.3"
}
}