create basic command handler

This commit is contained in:
Santiago Forero 2021-09-08 10:00:14 -05:00
parent 0c6107fd7a
commit afd621e6c1
4 changed files with 1287 additions and 0 deletions

7
commands/help.js Normal file
View File

@ -0,0 +1,7 @@
module.exports = {
name: 'help',
description: 'Get information 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: ')
},
};

70
index.js Normal file
View File

@ -0,0 +1,70 @@
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 => {
if(event.message == '!botlist') return 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: ')
if (!event.message.startsWith(prefix)) return;
const args = event.message.slice(prefix.length).trim().split(/ +/);
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')
})

1192
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

18
package.json Normal file
View File

@ -0,0 +1,18 @@
{
"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"
}
}