]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blob - data/rbot/plugins/lastfm.rb
ticket #18
[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" || params[:action] == "neighbours" then
13         params[:action]="neighbours"
14       end
15       data = open("http://ws.audioscrobbler.com/1.0/user/#{params[:user]}/#{params[:action]}.txt")
16       m.reply "#{params[:action]} for #{params[:user]}:"
17       m.reply data.to_a[0..3].map{|l| l.split(',')[-1].chomp}.join(", ")
18     rescue
19       m.reply "could not find #{params[:action]} for #{params[:user]} (is #{params[:user]} a user?)"
20     end
21   end
22 end
23
24 plugin = LastFmPlugin.new
25 plugin.map 'lastfm :action :user', :action => 'do_lastfm'