Guest User

Untitled

a guest
Apr 25th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. require 'scrobbler'
  2. require 'pstore'
  3.  
  4. class LastFm
  5. def initialize(bot)
  6. @bot = bot
  7.  
  8. @bot.bind(:command, method(:command))
  9.  
  10. @pstore = PStore.new('lastfm.db')
  11. end
  12.  
  13. def command(info, command, arguments)
  14. if command == "lp"
  15. username = @pstore.transaction(username) do
  16. @pstore[info[:nick].downcase]
  17. end
  18. username ||= info[:nick]
  19. username = arguments[0] if arguments[0]
  20. user = Scrobbler::User.new(username)
  21. last_track = user.recent_tracks.first
  22. if last_track.nil?
  23. @bot.raw "PRIVMSG #{info[:channel]} :That user (#{username}) does not exist!"
  24. else
  25. @bot.raw "PRIVMSG #{info[:channel]} :#{username}'s last track: #{last_track.name} - #{last_track.artist}"
  26. end
  27. elsif command == "lpset"
  28. @pstore.transaction do
  29. @pstore[info[:nick].downcase] = arguments[0]
  30. @bot.raw "NOTICE #{info[:nick]} :Your last.fm username was set to #{arguments[0]}"
  31. end
  32. end
  33. rescue StandardError => e
  34. puts "#{e.class}: #{e.message}"
  35. puts e.backtrace
  36. end
  37.  
  38. def unload
  39. @bot.unbind(:command, method(:command))
  40. end
  41. end
  42.  
  43. $plugin = LastFm
Add Comment
Please, Sign In to add comment