Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'scrobbler'
- require 'pstore'
- class LastFm
- def initialize(bot)
- @bot = bot
- @bot.bind(:command, method(:command))
- @pstore = PStore.new('lastfm.db')
- end
- def command(info, command, arguments)
- if command == "lp"
- username = @pstore.transaction(username) do
- @pstore[info[:nick].downcase]
- end
- username ||= info[:nick]
- username = arguments[0] if arguments[0]
- user = Scrobbler::User.new(username)
- last_track = user.recent_tracks.first
- if last_track.nil?
- @bot.raw "PRIVMSG #{info[:channel]} :That user (#{username}) does not exist!"
- else
- @bot.raw "PRIVMSG #{info[:channel]} :#{username}'s last track: #{last_track.name} - #{last_track.artist}"
- end
- elsif command == "lpset"
- @pstore.transaction do
- @pstore[info[:nick].downcase] = arguments[0]
- @bot.raw "NOTICE #{info[:nick]} :Your last.fm username was set to #{arguments[0]}"
- end
- end
- rescue StandardError => e
- puts "#{e.class}: #{e.message}"
- puts e.backtrace
- end
- def unload
- @bot.unbind(:command, method(:command))
- end
- end
- $plugin = LastFm
Add Comment
Please, Sign In to add comment