Преглед на файлове

Extract logic into separate methods

tags/Beta0.1
Tim Kuzhagaliyev преди 2 години
родител
ревизия
2bf7153758
променени са 1 файла, в които са добавени 19 реда и са изтрити 7 реда
  1. 19
    7
      lib/BansheeBot.js

+ 19
- 7
lib/BansheeBot.js Целия файл

@@ -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…
Отказ
Запис