cactus-irc/index.js

52 lines
1.2 KiB
JavaScript

const IRC = require('irc-framework')
const fs = require('fs')
const 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.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
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.join('#cactus-spam')
})