only post a radio update every 2 minutes

This commit is contained in:
reality 2015-07-20 15:13:01 +00:00
parent bfa4de5a1a
commit db25eadedf

View File

@ -11,6 +11,7 @@ var radio = function(dbot) {
this.data = false; this.data = false;
this.title = false; this.title = false;
this.stream = false; this.stream = false;
this.recentUpdate = false;
this.internalAPI = { this.internalAPI = {
'startRadio': function() { 'startRadio': function() {
var stream = icecast.createReadStream(this.config.stream); var stream = icecast.createReadStream(this.config.stream);
@ -37,11 +38,14 @@ var radio = function(dbot) {
this.title = icecast.parseMetadata(metadata).StreamTitle; this.title = icecast.parseMetadata(metadata).StreamTitle;
if(!_.isUndefined(this.title) && this.data['icy-name']) { // sowwy jesus if(!_.isUndefined(this.title) && this.data['icy-name']) { // sowwy jesus
_.each(this.config.announce, function(a) { _.each(this.config.announce, function(a) {
if(!this.recentUpdate) {
dbot.say(a.server, a.name, dbot.t('now_playing', { dbot.say(a.server, a.name, dbot.t('now_playing', {
'name': this.data['icy-name'], 'name': this.data['icy-name'],
'song': this.title, 'song': this.title,
'url': this.data['icy-url'] 'url': this.data['icy-url']
})); }));
recentUpdate = true;
}
}, this); }, this);
} }
}.bind(this)); }.bind(this));
@ -91,6 +95,10 @@ var radio = function(dbot) {
this.internalAPI.startRadio(); this.internalAPI.startRadio();
} }
}.bind(this)); }.bind(this));
dbot.api.timers.addTimer(120000, function() {
this.recentUpdate = false;
}.bind(this));
}.bind(this); }.bind(this);
this.onDestroy = function() { this.onDestroy = function() {
this.stream.end(); this.stream.end();