Created
November 11, 2015 21:27
-
-
Save camwhite/0d4497779e4a13c34ae0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Shows the playlist | |
name: '!playlist', | |
help: 'Skip the song if moderator, else place a vote to skip the song.', | |
types: ['message'], | |
regex: /^(!|\/)playlist$/, | |
action: function( chat, stanza ) { | |
let player = getPlayer( chat ); | |
let playlist = getPlaylist( chat ); | |
let tracks = []; | |
let trackIndex = 1; | |
for(let track of playlist) { | |
tracks.push(trackIndex++ + ': ' + track.title) | |
} | |
const maxTracksPerMessage = 21; | |
let chunks = 1; | |
let chunker = (tracks) => { | |
if(tracks.length > maxTracksPerMessage) { | |
let start = 0; | |
let end = start == tracks.length ? tracks.length : maxTracksPerMessage; | |
chunks = Math.ceil(tracks.length / maxTracksPerMessage); | |
while(chunks > 0) { | |
let chunk = tracks.slice(start, end).join('\n'); | |
chat.sendMessage( chunk ); | |
start+=maxTracksPerMessage; | |
end+=maxTracksPerMessage; | |
chunks--; | |
} | |
} | |
else { | |
let prettyPlaylist = tracks.join('\n'); | |
chat.sendMessage( prettyPlaylist ); | |
} | |
} | |
chunker(tracks); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment