Browse Source

Extract logic into separate methods

pull/1/head
Tim Kuzhagaliyev 5 years ago
parent
commit
2bf7153758
  1. 26
      lib/BansheeBot.js

26
lib/BansheeBot.js

@ -30,22 +30,34 @@ class BansheeBot { @@ -30,22 +30,34 @@ class BansheeBot {
.then(() => console.log('Connected!'))
.then(() => console.log('Searching for the music channel...'))
.then(() => this.findMusicChannel())
.then(musicChannel => this.musicChannel = musicChannel)
.then(() => console.log('Channel found!'))
.then(() => console.log('Bootstrapping to Last.fm...'))
.then(()=> this.prepareLastFm())
.then(() => console.log('Done!'))
.catch(error => console.error(error));
}
findMusicChannel() {
return Promise.resolve()
.then(() => this.client.channels.find(channel => channel.name && channel.name.match(/^music/i)))
.then(channel => {
if (!channel) throw new Error('Could not find the music channel!');
this.musicChannel = channel;
})
return channel;
});
}
.then(() => console.log('Connecting to Last.fm stream...'))
.then(() => lastfm.stream(this.config.lastFmUsername))
prepareLastFm() {
return Promise.resolve()
.then(() => this.lastfm.stream(this.config.lastFmUsername))
.then(lastFmStream => {
lastFmStream.on('nowPlaying', (track) => {
this.musicChannel.send('Now playing: ' + track.name);
});
})
.then(() => console.log('Connected!'))
.catch(error => console.error(error));
}
}

Loading…
Cancel
Save