Class: LastFM
- Inherits:
-
Object
- Object
- LastFM
- Includes:
- Cinch::Plugin
- Defined in:
- lib/rateless_bot/plugins/lastfm.rb
Instance Method Summary collapse
- #execute(m) ⇒ Object
- #help ⇒ Object
-
#initialize(*args) ⇒ LastFM
constructor
A new instance of LastFM.
- #make_track_str(track) ⇒ Object
Constructor Details
#initialize(*args) ⇒ LastFM
Returns a new instance of LastFM.
11 12 13 14 |
# File 'lib/rateless_bot/plugins/lastfm.rb', line 11 def initialize(*args) super @lastfm = Lastfm.new(config[:api_key], config[:api_secret]) end |
Instance Method Details
#execute(m) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/rateless_bot/plugins/lastfm.rb', line 18 def execute(m) user = m..split('!lastfm ')[1] scrobbles = @lastfm.user.get_recent_tracks(:user => user) track = scrobbles[0] m.reply make_track_str(track) end |
#help ⇒ Object
5 6 7 |
# File 'lib/rateless_bot/plugins/lastfm.rb', line 5 def help '!lastfm USERNAME - get a given user\'s most recently scrobbled track' end |
#make_track_str(track) ⇒ Object
27 28 29 30 31 |
# File 'lib/rateless_bot/plugins/lastfm.rb', line 27 def make_track_str(track) artist_and_title = track['artist']['content'] + ' - ' + track['name'] artist_and_title + (track['nowplaying'] ? ' [Now Playing]' : '') end |