Browse files

add empty playlist to toggle to, fixes #10

  • Loading branch information...
1 parent 496d100 commit 6dfc0fb9990599955377f799d17b3e98e1dc9577 Mac Angell committed Mar 3, 2013
Showing with 51 additions and 2 deletions.
  1. +51 −2 lib/DjAddOn.js
View
53 lib/DjAddOn.js
@@ -2,8 +2,29 @@
module.exports = function DjAddOn(bot) {
- var playlistName = 'bot',
- emptyPlaylistNAme = 'empty',
+ var playlistName = 'default',
+ emptyPlaylistName = 'empty',
+ _ = require('underscore'),
+ initialize = function() {
+ bot.on('connect', function() {
+ bot.playlistListAll(function(data) {
+ console.log(data);
+ if (data.success) {
+ if (!_.some(data.list, function(list) { return list.name === emptyPlaylistName; })) {
+ bot.playlistCreate(emptyPlaylistName);
+ }
+ if (!_.some(data.list, function(list) { return list.name === playlistName; })) {
+ bot.playlistCreate(playlistName);
+ }
+ _.each(data.list, function(list) {
+ if (list.name !== playlistName && list.name !== emptyPlaylistName) {
+ bot.playlistDelete(list.name);
+ }
+ });
+ }
+ });
+ });
+ },
dj = function(msgData, issuerId, replyFunc) {
bot.addDj();
replyFunc('Ok, hope you are prepared for my playlist!');
@@ -86,6 +107,24 @@ module.exports = function DjAddOn(bot) {
else {
replyFunc('I\'m not currently playing a song');
}
+ },
+ togglePlaylist = function(msgData, issuerId, replyFunc) {
+ bot.playlistListAll(function(data) {
+ if (data.success) {
+ var to, active = _.find(data.list, function(list) {
+ return list.active;
+ });
+ if (active.name === playlistName) {
+ to = emptyPlaylistName;
+ bot.playlistSwitch(emptyPlaylistName);
+ }
+ else if (active.name === emptyPlaylistName) {
+ to = playlistName;
+ bot.playlistSwitch(playlistName);
+ }
+ replyFunc('Switched to playlist: ' + to);
+ }
+ });
};
this.name = 'dj';
@@ -134,12 +173,22 @@ module.exports = function DjAddOn(bot) {
help: 'lists next 10 songs queued up in the bot\'s playlist',
moderatorOnly: false,
action: announceTopSongs
+ },
+ {
+ primaryCommand: '/togglepl',
+ secondaryCommands: [],
+ help: 'toggles between the bot\'s playlist and an empty one',
+ moderatorOnly: true,
+ action: togglePlaylist
}
];
this.enable = function() {
+
};
this.disable = function() {
};
+
+ initialize();
};

0 comments on commit 6dfc0fb

Please sign in to comment.