summaryrefslogtreecommitdiff
path: root/data
diff options
context:
space:
mode:
authorRaine Virta <rane@kapsi.fi>2009-12-13 22:31:14 +0200
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2009-12-21 10:30:44 +0100
commit4fa049e0386d8044f0063e90b7e7efbca9c712de (patch)
tree100dc93fe10560b4835bfffe19de9ec4efc5285a /data
parent0f4d8db41a58cdbb0f302e828e1e84b2752344b3 (diff)
add spotify plugin
Diffstat (limited to 'data')
-rw-r--r--data/rbot/plugins/spotify.rb66
1 files changed, 66 insertions, 0 deletions
diff --git a/data/rbot/plugins/spotify.rb b/data/rbot/plugins/spotify.rb
new file mode 100644
index 00000000..f645a8af
--- /dev/null
+++ b/data/rbot/plugins/spotify.rb
@@ -0,0 +1,66 @@
+#-- vim:sw=2:et
+#++
+#
+# :title: spotify plugin for rbot
+#
+# Author:: Raine Virta <raine.virta@gmail.com>
+#
+# Copyright:: (C) 2009 Raine Virta
+#
+# License:: GPL v2
+
+class SpotifyPlugin < Plugin
+ def help(plugin, topic)
+ _("spotify plugin - usage: spotify <spotify>, spotify artist <artist>, spotify album <album>")
+ end
+
+ def search(m, params)
+ method = params[:method] || 'track'
+ result = Spotify.search(method, params[:query].to_s)
+
+ if result.nil?
+ m.reply "no results"
+ return
+ end
+
+ case method
+ when 'track'
+ reply = _("%{b}%{artist}%{b} – %{track}") % {
+ :artist => result.artist.name,
+ :track => result.name,
+ :b => Bold
+ }
+
+ if result.album.released
+ reply << _(" [%{u}%{album}%{u}, %{released}]") % {
+ :released => result.album.released,
+ :album => result.album.name,
+ :u => Underline
+ }
+ else
+ reply << _(" [%{u}%{album}%{u}]") % { :album => result.album.name, :u => Underline }
+ end
+
+ reply << _(" — %{url}") % { :url => result.url }
+ when 'artist'
+ reply = _("%{b}%{artist}%{b} — %{url}") % {
+ :b => Bold,
+ :artist => result.name,
+ :url => result.url
+ }
+ when 'album'
+ reply = _("%{b}%{artist}%{b} – %{u}%{album}%{u} — %{url}") % {
+ :b => Bold,
+ :u => Underline,
+ :artist => result.artist.name,
+ :album => result.name,
+ :url => result.url
+ }
+ end
+
+ m.reply reply
+ end
+end
+
+plugin = SpotifyPlugin.new
+plugin.map 'spotify [:method] *query', :action => :search, :requirements => { :method => /track|artist|album/ }