Skip to content

Instantly share code, notes, and snippets.

@ciaran
Created March 10, 2009 10:34
Show Gist options
  • Save ciaran/76847 to your computer and use it in GitHub Desktop.
Save ciaran/76847 to your computer and use it in GitHub Desktop.
plugin do
def tinysong(title, artist)
response = Net::HTTP.new("tinysong.com").start do |h|
req = Net::HTTP::Get.new("?s=#{URI.escape "#{t.name} by #{t.artist}"}")
r.add_field("X-Requested-With", "XMLHttpRequest")
h.request(req)
end
response.body =~ %r{"(http:\\/\\/tinysong.com.+?)"} ? $1.gsub("\\", "") : nil
end
commands do |message, sender|
case message
when /^#{Kirby::NICK}: help/
say "CHOON PLUGIN"
say "choon [<user>] : Displays the currently playing choon for last.fm user <user>. If <user> is omitted, it uses the IRC nick of the person saying 'choon', and tries mapping it onto a last.fm user using an internal username map."
when /^(?i)choo+n(\s+(\w+))?/
user_map = {'carl'=>'carldr','tony'=>'langdale','ciaran'=>'Ciaran','greg'=>'gspiers'}
%w{open-uri rubygems hpricot scrobble.rb}.map{|a|require a}
if $2.nil?
nick = user_map[arg = sender]
elsif user_map[$2]
nick = user_map[arg = $2]
else
arg = nick = $2
end
user = Scrobble::User.new(nick)
if user and track = user.currently_playing
say "#{arg} is playing '#{track.name}' by #{track.artist} - #{tinysong(track.name, track.artist)}"
else
say "#{arg} isn't playing anything right now."
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment