add hacky fix for radio stopping

This commit is contained in:
notnull 2020-02-23 19:36:38 -05:00
parent 8048822859
commit d67835be30
3 changed files with 16 additions and 1 deletions

2
.gitignore vendored
View File

@ -2,3 +2,5 @@ node_modules
old old
.env .env
playlists/* playlists/*
test

View File

@ -2,7 +2,7 @@ const IRC = require('irc-framework')
const bot = new IRC.Client() const bot = new IRC.Client()
const { searchTrack, requestTrack, deleteTrack } = require('./spotify') 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 { getMyPlaylist } = require('./linx-commands')
const chalk = require('chalk') const chalk = require('chalk')
@ -11,6 +11,7 @@ const helpers = ['notnull', 'rfa', 'substack']
const autojoin = ['#anarchybots'] const autojoin = ['#anarchybots']
setInterval(poll, 60000)
const host = process.env.HOST || 'localhost' const host = process.env.HOST || 'localhost'
const port = process.env.PORT || 6667 const port = process.env.PORT || 6667
const nick = process.env.NICK || 'radiobot' const nick = process.env.NICK || 'radiobot'

View File

@ -1,11 +1,22 @@
const { spawnSync } = require('child_process') const { spawnSync } = require('child_process')
const fs = require('fs') const fs = require('fs')
let playing = null
const getPlaylist = () => { const getPlaylist = () => {
const { stderr, stdout } = spawnSync('mpc', ['playlist']) const { stderr, stdout } = spawnSync('mpc', ['playlist'])
return { error: stderr.toString(), playlist: stdout.toString() } 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 getCurrentTrack = () => {
const { stderr, stdout } = spawnSync('mpc', ['current']) const { stderr, stdout } = spawnSync('mpc', ['current'])
return { error: stderr.toString(), track: stdout.toString() } return { error: stderr.toString(), track: stdout.toString() }
@ -108,4 +119,5 @@ module.exports = {
insertTrack, insertTrack,
removeTrack, removeTrack,
reset, reset,
poll,
} }