wrzucamy śmietnik :DDDD
This commit is contained in:
parent
6d3524eed5
commit
cded4e036a
10 changed files with 2296 additions and 0 deletions
47
index.js
Normal file
47
index.js
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
const config = require('./config.json')
|
||||
const IRC = require('irc-framework')
|
||||
const fs = require('node:fs')
|
||||
|
||||
const bot = new IRC.Client()
|
||||
// for convinience's sake
|
||||
bot.config = config
|
||||
bot.prefix = config.bot.prefix
|
||||
|
||||
bot.commands = []
|
||||
const commandsFolder = fs.readdirSync('./commands/')
|
||||
for (const file of commandsFolder) {
|
||||
const command = require(`./commands/${file}`)
|
||||
if ('data' in command && 'execute' in command) {
|
||||
bot.commands[command.data.name] = command
|
||||
console.log(`loaded command: ${command.data.name}`)
|
||||
} else {
|
||||
console.log(`failed to load file ${file}, it's missing "data" or "execute" property`)
|
||||
}
|
||||
}
|
||||
|
||||
bot.connect({
|
||||
host: config.irc.server,
|
||||
port: config.irc.port,
|
||||
nick: config.irc.nick,
|
||||
password: config.irc.password
|
||||
})
|
||||
|
||||
bot.on('registered', function() {
|
||||
console.log('connected ok!')
|
||||
bot.join(config.irc.channel)
|
||||
})
|
||||
|
||||
bot.on('message', async function(event) {
|
||||
if (event.message.toString().startsWith(bot.prefix)) {
|
||||
let sentCommand = event.message.toString().split(bot.prefix)[1].toString().split(' ')[0]
|
||||
if (bot.commands[sentCommand]) {
|
||||
try {
|
||||
await bot.commands[sentCommand].execute(event, bot)
|
||||
console.log(event)
|
||||
} catch (err) {
|
||||
event.reply('Oops, something went horribly wrong when executing this command...')
|
||||
console.error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue