summaryrefslogtreecommitdiff
path: root/data/rbot/plugins/lastfm.rb
blob: 81b203f6a74e8a5b36717050e2a018a3bf56cc3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
require 'open-uri'

# plugin submitted by Jeremy Voorhis (jvoorhis)

class LastFmPlugin < Plugin
  def help(plugin, topic="")
    "lastfm <function> <user> => lastfm data for <user> on last.fm where <function> in [recenttracks, topartists, topalbums, toptracks, tags, friends, neighbors]"
  end

  def do_lastfm (m, params)
    begin
      if params[:action] == "neighbors" then
        params[:action]="neighbours"
      elsif params[:action] == "neighbours" then
        m.reply "Thats not how you spell neighbors, you dolt!"
        return
      end
      data = open("http://ws.audioscrobbler.com/1.0/user/#{params[:user]}/#{params[:action]}.txt")
      m.reply "#{params[:action]} for #{params[:user]}:"
      data.to_a[0..2].each do |line|
        m.reply line.split(',')[-1]
      end
    rescue
      m.reply "could not find #{params[:action]} for #{params[:user]} (is #{params[:user]} a user?)"
    end
  end
end

plugin = LastFmPlugin.new
plugin.map 'lastfm :action :user', :action => 'do_lastfm'