Class: LastFM

Inherits:
Object
  • Object
show all
Includes:
Cinch::Plugin
Defined in:
lib/rateless_bot/plugins/lastfm.rb

Instance Method Summary collapse

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.message.split('!lastfm ')[1]
  scrobbles = @lastfm.user.get_recent_tracks(:user => user)
  track = scrobbles[0]


  m.reply make_track_str(track)
end

#helpObject



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