From d67835be30b8bfa52f69d74555d1027d7859125b Mon Sep 17 00:00:00 2001 From: notnull Date: Sun, 23 Feb 2020 19:36:38 -0500 Subject: [PATCH] add hacky fix for radio stopping --- .gitignore | 2 ++ src/irc-bot.js | 3 ++- src/mpc-commands.js | 12 ++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) 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..57e09b0 100644 --- a/src/mpc-commands.js +++ b/src/mpc-commands.js @@ -1,11 +1,22 @@ const { spawnSync } = require('child_process') const fs = require('fs') +let playing = null + const getPlaylist = () => { const { stderr, stdout } = spawnSync('mpc', ['playlist']) return { error: stderr.toString(), playlist: stdout.toString() } } +const poll = () => { + const { stdout } = spawnSync('mpc', ['status']) + const nowPlaying = stdout.toString() + if (playing === nowPlaying) { + console.log('Song stopped playing. Skipping\n', nowPlaying) + spawnSync('mpc', ['next']) + } else playing = nowPlaying +} + const getCurrentTrack = () => { const { stderr, stdout } = spawnSync('mpc', ['current']) return { error: stderr.toString(), track: stdout.toString() } @@ -108,4 +119,5 @@ module.exports = { insertTrack, removeTrack, reset, + poll, }