+ m.reply "I had problems getting #{user}'s current info"
+ end
+ end
+
+ def find_artist(m, params)
+ artist = params[:who].to_s
+ page = nil
+ begin
+ esc = URI.escape(CGI.escape(artist))
+ page = @bot.httputil.get "#{LASTFM}/music/#{esc}"
+ if page
+ if page.match(/<h1 class="h1artist"><a href="([^"]+)">(.*?)<\/a><\/h1>/)
+ url = LASTFM + $1
+ title = $2.ircify_html
+ else
+ raise "No URL/Title found for #{artist}"
+ end
+
+ wiki = "This artist doesn't have a description yet. You can help by writing it: #{url}/+wiki?action=edit"
+ if page.match(/<div (?:class|id)="wikiAbstract">(.*?)<\/div>/m)
+ wiki = $1.ircify_html
+ end
+
+ m.reply "%s : %s\n%s" % [title, url, wiki], :overlong => :truncate
+ else
+ m.reply "no data found on #{artist}"
+ return
+ end
+ rescue Exception => e
+ m.reply "I had problems looking for #{artist}"
+ error e.inspect
+ debug e.backtrace.join("\n")
+ debug page[0...10*1024] if page
+ return
+ end
+ end
+
+ def find_track(m, params)
+ m.reply "not implemented yet, sorry"
+ end
+
+ def find_album(m, params)
+ m.reply "not implemented yet, sorry"
+ end
+
+ def set_user(m, params)
+ user = params[:who].to_s
+ nick = m.sourcenick
+ @registry[ nick ] = user
+ m.reply "Ok, I'll remember that #{nick} is #{user} at last.fm"
+ end
+
+ def get_user(m, params)
+ nick = ""
+ if params[:who] then
+ nick = params[:who].to_s
+ else
+ nick = m.sourcenick
+ end
+ if @registry.has_key?( nick ) then
+ user = @registry[ nick ]
+ m.reply "#{nick} is #{user} at last.fm"
+ else
+ m.reply "Sorry, I don't know who #{nick} is at last.fm perhaps you need to: lastfm set <username>"
+ end
+ end
+
+ def lastfm(m, params)
+ action = params[:action].intern
+ action = :neighbours if action == :neighbors
+ user = nil
+ if params[:user] then
+ user = params[:user].to_s
+ elsif @registry.has_key? ( m.sourcenick ) then
+ user = @registry[ m.sourcenick ]
+ else
+ # m.reply "I don't know who you are on last.fm. Use 'lastfm set username' to identify yourself."
+ # return
+ user = m.sourcenick
+ end
+ begin
+ data = @bot.httputil.get("http://ws.audioscrobbler.com/1.0/user/#{user}/#{action}.txt")
+ m.reply "#{action} for #{user}:"
+ m.reply data.to_a[0..3].map{|l| l.split(',',2)[-1].chomp}.join(", ")
+ rescue
+ m.reply "could not find #{action} for #{user} (is #{user} a user?). perhaps you need to: lastfm set <username>"