Permalink
Browse files

added last fm key/secret as options

  • Loading branch information...
Mac Angell
Mac Angell committed Mar 14, 2013
1 parent 5ce14c0 commit 11196f3355e7861bebfe87bdf19ac1a1271f6dc2
Showing with 45 additions and 10 deletions.
  1. +4 −0 README.md
  2. +9 −1 app.js
  3. +32 −9 lib/LastFmAddOn.js
View
@@ -38,6 +38,8 @@ You can run ttfm-bot with the -h flag to see the various options:
-n, --db-name <name> The Mongo DB to connect to Defaults to: "ttfm"
-U, --db-user <user> The Mongo DB user
-p, --db-password <password> The Mongo DB password
+ -l, --lastfm-api-key <key> The last.fm API key
+ -L, --lastfm-secret <secret> The last.fm secret
Example usage:
@@ -273,6 +275,8 @@ Add ons that come with this bot
* <code>song-tracker</code> - Requires a MongoDB instance. Tracks songs that have been played and announces information about those songs.
* <code>user-tracker</code> - Requires a MongoDB instance. Tracks user's activity in the room including songs they've played, voted for, and votes they've recieved.
* <code>achievements-tracker</code> - Requires a MongoDB instance. Adds an achievements system to the room, and tracks achievements that people have earned.
+* <code>lastfm</code> - Requires a [last.fm API key and secret](http://www.last.fm/api). Provides commands for retrieving artist info, similar artists and songs.
+* <code>voting</code> - Creates a system for having users participate in a vote via chat.
License
===
View
10 app.js
@@ -40,6 +40,14 @@ var options = {
dbPassword: {
argument: 'password',
description: 'The Mongo DB password'
+ },
+ lastFmApiKey: {
+ argument: 'key',
+ description: 'The last.fm API key'
+ },
+ lastFmSecret: {
+ argument: 'secret',
+ description: 'The last.fm secret'
}
},
config = opter(options, version);
@@ -102,7 +110,7 @@ bot.registerAddOn(DjAddOn);
bot.registerAddOn(DjQueueAddOn, { djSongLimit: 2 });
// register lastfm addon
-bot.registerAddOn(LastFmAddOn);
+bot.registerAddOn(LastFmAddOn, { lastFmApiKey: config.lastFmApiKey, lastFmSecret: config.lastFmSecret });
// register voting addon
bot.registerAddOn(VotingAddOn);
View
@@ -3,19 +3,15 @@
module.exports = function LastFmAddOn(bot) {
var _ = require('underscore'),
- lastFmApiKey = process.env.lastFmApiKey || '',
- lastFmSecret = process.env.lastFmSecret || '',
LastFmNode = require('lastfm').LastFmNode,
- lastfm = new LastFmNode({
- api_key: lastFmApiKey,
- secret: lastFmSecret
- }),
+ lastfm = null,
+ self = this,
cleanUpAndLimitText = function(text, size) {
return text.replace(/<.*?>/gi, '').replace('\n', '').replace(/\s+/g, ' ').substr(0, size) + '...';
},
getArtistInfo = function(msgData, issuerId, replyFunc) {
var currentSong = bot.getCurrentSong();
- if (currentSong) {
+ if (currentSong && lastfm) {
lastfm.request('artist.getInfo', {
artist: currentSong.artist,
handlers: {
@@ -35,7 +31,7 @@ module.exports = function LastFmAddOn(bot) {
},
getSimilarArtist = function(msgData, issuerId, replyFunc) {
var currentSong = bot.getCurrentSong();
- if (currentSong) {
+ if (currentSong && lastfm) {
lastfm.request('artist.getInfo', {
artist: currentSong.artist,
handlers: {
@@ -57,7 +53,7 @@ module.exports = function LastFmAddOn(bot) {
},
getSimilarSong = function(msgData, issuerId, replyFunc) {
var currentSong = bot.getCurrentSong();
- if (currentSong) {
+ if (currentSong && lastfm) {
lastfm.request('track.getSimilar', {
artist: currentSong.artist,
track: currentSong.song.replace(/\(.*?\)/gi, ''),
@@ -78,6 +74,18 @@ module.exports = function LastFmAddOn(bot) {
else {
replyFunc('There is no song playing at the moment.');
}
+ },
+ lastFmDetailsChangeHandler = function(oldValue, newValue) {
+ if (self.options.lastFmApiKey.value.length > 0 &&
+ self.options.lastFmApiKey.value.length > 0) {
+ lastfm = new LastFmNode({
+ api_key: self.options.lastFmApiKey.value,
+ secret: self.options.lastFmSecret.value
+ });
+ }
+ else {
+ lastfm = null;
+ }
};
this.name = 'lasfm';
@@ -108,6 +116,21 @@ module.exports = function LastFmAddOn(bot) {
}
];
+ this.options = {
+ lastFmApiKey: {
+ value: '',
+ type: String,
+ description: 'The last.fm API key needed to call the services.',
+ onChange: lastFmDetailsChangeHandler
+ },
+ lastFmSecret: {
+ value: '',
+ type: String,
+ description: 'The last.fm secret needed to call the services.',
+ onChange: lastFmDetailsChangeHandler
+ }
+ };
+
this.enable = function() {
//bot.on('registered', registeredHandler);
};

0 comments on commit 11196f3

Please sign in to comment.