cactus-irc/index.js

74 lines
1.2 KiB
JavaScript

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')
})