create basic command handler
This commit is contained in:
parent
0c6107fd7a
commit
afd621e6c1
|
@ -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: ')
|
||||
},
|
||||
};
|
|
@ -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')
|
||||
})
|
||||
|
File diff suppressed because it is too large
Load Diff
|
@ -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"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue