]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blob - data/rbot/plugins/lastfm.rb
81b203f6a74e8a5b36717050e2a018a3bf56cc3d
[user/henk/code/ruby/rbot.git] / 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       if params[:action] == "neighbors" then
13         params[:action]="neighbours"
14       elsif params[:action] == "neighbours" then
15         m.reply "Thats not how you spell neighbors, you dolt!"
16         return
17       end
18       data = open("http://ws.audioscrobbler.com/1.0/user/#{params[:user]}/#{params[:action]}.txt")
19       m.reply "#{params[:action]} for #{params[:user]}:"
20       data.to_a[0..2].each do |line|
21         m.reply line.split(',')[-1]
22       end
23     rescue
24       m.reply "could not find #{params[:action]} for #{params[:user]} (is #{params[:user]} a user?)"
25     end
26   end
27 end
28
29 plugin = LastFmPlugin.new
30 plugin.map 'lastfm :action :user', :action => 'do_lastfm'