(.*?)<\/a><\/h1>/)
+ url = LASTFM + $1
+ title = $2.ircify_html
else
- m.reply "no data found on #{artist}"
+ 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>/m)
+ wiki = $1.ircify_html
end
- rescue
- m.reply "I had problems looking for #{artist}"
- debug page
+
+ m.reply "%s : %s\n%s" % [title, url, wiki], :overlong => :truncate
+ else
+ m.reply "no data found on #{artist}"
return
end
- when :song, :track
- m.reply "not implemented yet, sorry"
- when :album
- m.reply "not implemented yet, sorry"
- else
- return usage unless what.length == 1
- user = what.first
- begin
- data = open("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?)"
- 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 lastfm(m, params)
+ action = params[:action].intern
+ action = :neighbours if action == :neighbors
+ user = params[:user]
+ 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?)"
end
end
end
plugin = LastFmPlugin.new
-plugin.map 'lastfm :action *what'
+plugin.map 'lastfm [:num] event[s] in *location', :action => :find_event, :requirements => { :num => /\d+/ }, :thread => true
+plugin.map 'lastfm [:num] event[s] by *who', :action => :find_event, :requirements => { :num => /\d+/ }, :thread => true
+plugin.map 'lastfm [:num] event[s] [for] *who', :action => :find_event, :requirements => { :num => /\d+/ }, :thread => true
+plugin.map 'lastfm artist *who', :action => :find_artist, :thread => true
+plugin.map 'lastfm group *who', :action => :find_artist, :thread => true
+plugin.map 'lastfm track *dunno', :action => :find_track
+plugin.map 'lastfm song *dunno', :action => :find_track
+plugin.map 'lastfm album *dunno', :action => :find_album
+plugin.map 'lastfm :action *user', :thread => true