lastfm plugin from Jeremy Voorhis :)
[rbot] / data / rbot / plugins / lastfm.rb
1 require 'open-uri'
2
3 # plugin submitted by Jeremy Voorhis (jvoorhis)
4  
5 class LastFmPlugin < Plugin
6   def help(plugin, topic="")
7     "lastfm <function> <user> => lastfm data for <user> on last.fm where <function> in [recenttracks, topartists, topalbums, toptracks, tags, friends, neighbors]"
8   end
9  
10   def do_lastfm (m, params)
11     begin
12       data = open("http://ws.audioscrobbler.com/1.0/user/#{params[:user]}/#{params[:action]}.txt")
13       m.reply "#{params[:action]} for #{params[:user]}:"
14       data.to_a[0..2].each do |line|
15         m.reply line.split(',')[-1]
16       end
17     rescue
18       m.reply "could not find #{params[:action]} for #{params[:user]} (is #{params[:user]} a user?)"
19     end
20   end
21 end
22  
23 plugin = LastFmPlugin.new
24 plugin.map 'lastfm :action :user', :action => 'do_lastfm'