- pre_events.each { |day, month, year, url_who, who, url_where, where, how_many|
- date = Time.utc(year.to_i, month.to_i, day.to_i)
- url = LASTFM + url_who
- if who.match(/<strong>(.*?)<\/strong>(.+)?/)
- artist = Bold + $1.ircify_html + Bold
- artist << ", " << $2.ircify_html if $2
- else
- debug "who: #{who.inspect}"
- artist = who.ircify_html
- end
- if where.match(/<strong>(.*?)<\/strong>(?:<br\s*\/>(.+)?)?/)
- loc = Bold + $1.ircify_html + Bold
- loc << ", " << $2.ircify_html if $2
- else
- debug where.inspect
- loc = where.ircify_html
- end
- attendance = how_many.ircify_html
- events << LastFmEvent.new(url, date, artist, loc, attendance)
- }
- # debug events.inspect
-
- events[0...num].each { |event|
- disp_events << event.to_s
- }
- m.reply disp_events.join(' | '), :split_at => /\s+\|\s+/
+ if where.match(/<strong>(.*?)<\/strong>(?:<br\s*\/>(.+)?)?/)
+ loc = Bold + $1.ircify_html + Bold
+ loc << ", " << $2.ircify_html if $2
+ else
+ debug where.inspect
+ loc = where.ircify_html
+ end
+ attendance = how_many ? how_many.ircify_html : ''
+ events << LastFmEvent.new(url, date, artist, loc, attendance)
+ } }
+ # debug events.inspect
+
+ events[0...num].each { |event|
+ disp_events << event.to_s
+ }
+ m.reply disp_events.join(' | '), :split_at => /\s+\|\s+/
+ else
+ m.reply "No events found #{spec}"
+ return
+ end
+ rescue Exception => e
+ m.reply "I had problems looking for events #{spec}"
+ error e.inspect
+ debug e.backtrace.join("\n")
+ debug page[0...10*1024] if page
+ return
+ end
+ end
+
+ def now_playing(m, params)
+ opts = { :cache => false }
+ user = nil
+ if params[:who] then
+ user = params[:who].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
+ page = nil
+ begin
+ page = @bot.httputil.get("#{LASTFM}/user/#{user}", opts)
+ if page
+ if page.match(/class="nowListening">\s*<td class="subject">\s*<a href="\/music.*?">(.*)<\/a>\s*<\/td/)
+ m.reply "#{user} is jammin to #{$1.ircify_html}"