diff --git a/.gitignore b/.gitignore index 5a27000..5394e37 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ node_modules old .env playlists/* + +test diff --git a/src/irc-bot.js b/src/irc-bot.js index 9ffe949..00a0b17 100644 --- a/src/irc-bot.js +++ b/src/irc-bot.js @@ -2,7 +2,7 @@ const IRC = require('irc-framework') const bot = new IRC.Client() const { searchTrack, requestTrack, deleteTrack } = require('./spotify') -const { getCurrentTrack, skipTrack, reset } = require('./mpc-commands') +const { getCurrentTrack, skipTrack, reset, poll } = require('./mpc-commands') const { getMyPlaylist } = require('./linx-commands') const chalk = require('chalk') @@ -11,6 +11,7 @@ const helpers = ['notnull', 'rfa', 'substack'] const autojoin = ['#anarchybots'] +setInterval(poll, 60000) const host = process.env.HOST || 'localhost' const port = process.env.PORT || 6667 const nick = process.env.NICK || 'radiobot' diff --git a/src/mpc-commands.js b/src/mpc-commands.js index 1be0afa..62f3cff 100644 --- a/src/mpc-commands.js +++ b/src/mpc-commands.js @@ -1,11 +1,21 @@ const { spawnSync } = require('child_process') const fs = require('fs') +const playing = null + const getPlaylist = () => { const { stderr, stdout } = spawnSync('mpc', ['playlist']) return { error: stderr.toString(), playlist: stdout.toString() } } +const poll = () => { + const { stdout } = spawnSync('mpc', ['status']) + console.log('testing for radio stop:', stdout.toString()) + const nowPlaying = stdout.toString() + if (nowPlaying === playing) spawnSync('mpc', ['next']) + else playing === nowPlaying +} + const getCurrentTrack = () => { const { stderr, stdout } = spawnSync('mpc', ['current']) return { error: stderr.toString(), track: stdout.toString() } @@ -108,4 +118,5 @@ module.exports = { insertTrack, removeTrack, reset, + poll, }