const IRC = require('irc-framework') const bot = new IRC.Client() const { getPlaylist, getCurrentTrack, skipTrack } = require('./mpc-commands') const { searchTrack, requestTrack } = require('./spotify') const chalk = require('chalk') const owners = ['notnull'] const autojoin = ['#anarchybots'] const host = process.env.HOST || 'localhost' const port = process.env.PORT || 6667 const nick = process.env.NICK || 'radiobot' console.log(chalk.magenta('\n***********************************\n')) console.log(chalk.magenta(`Connecting to ${host}\n`)) console.log(chalk.magenta('***********************************\n')) bot.connect({ host, port, nick }) bot.on('message', event => logEvent(event)) bot.on('connected', () => autojoin.map(c => bot.join(c))) bot.on('socket close', () => console.log('bot has disconnected.')) bot.matchMessage(/^!hello/, event => event.reply('Hi!')) /** ADMIN COMMANDS **/ bot.matchMessage(/^!join/, event => handleJoin(event)) bot.matchMessage(/^!part/, event => handlePart(event)) bot.matchMessage(/^!quit/, event => handleQuit(event)) /** RADIO COMMANDS**/ bot.matchMessage(/^!playlist/, event => sendPlaylist(event)) bot.matchMessage(/^!request/, event => requestTrack(event)) bot.matchMessage(/^!search/, event => searchTrack(event)) bot.matchMessage(/^!skip/, event => sendSkipTrack(event)) bot.matchMessage(/^!np/, event => sendCurrentTrack(event)) const handleJoin = event => { if (!owners.includes(event.nick)) return bot.join(event.message.split(' ')[1]) } const handlePart = event => { if (!owners.includes(event.nick)) return bot.part(event.message.split(' ')[1]) } const handleQuit = event => { if (!owners.includes(event.nick)) return bot.quit(["You'll cowards, don't even smoke crack."]) } const sendPlaylist = event => { const { error, playlist } = getPlaylist() if (error) return event.reply('Something went wrong.') const splitPlaylist = playlist.split('\n').slice(0, 5) splitPlaylist.map(s => bot.say(event.nick, s)) } const sendCurrentTrack = event => { const { error, track } = getCurrentTrack() if (error) return event.reply('Something went wrong.') if (track.length === 0) return event.reply('Nothing is currently playing.') event.reply(track) } const sendSkipTrack = event => { const { error, skip } = skipTrack() if (error) return event.reply('Something went wrong.') event.reply(`Track skipped: ${skip}`) } const logEvent = event => { if (event.type === 'notice') console.log(event.message) } module.exports = bot