]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/quotes.rb
+ (rss.rb) monkey-patch some basic common api over different rss item impls
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / quotes.rb
index 7ad6d570848b0b7d3b70c07f20d8645b26afdda3..50ca326ccc8c3325b4cff62d6ea5ce27bdc69a53 100644 (file)
@@ -56,6 +56,10 @@ class QuotePlugin < Plugin
     super
   end
 
+  def lastquote(channel)
+    @lists[channel].length-1
+  end
+
   def addquote(source, channel, quote)
     @lists[channel] = Array.new if(!@lists.has_key?(channel))
     num = @lists[channel].length 
@@ -120,25 +124,27 @@ class QuotePlugin < Plugin
   end
 
   def help(plugin, topic="")
-    case topic
+    case plugin
     when "addquote"
-      return "addquote [<channel>] <quote> => Add quote <quote> for channel <channel>. You only need to supply <channel> if you are addressing #{@bot.nick} privately. Responds to !addquote without addressing if so configured"
+      _("addquote [<channel>] <quote> => Add quote <quote> for channel <channel>. You only need to supply <channel> if you are addressing %{nick} privately.") % { :nick => @bot.nick }
     when "delquote"
-      return "delquote [<channel>] <num> => delete quote from <channel> with number <num>. You only need to supply <channel> if you are addressing #{@bot.nick} privately. Responds to !delquote without addressing if so configured"
+      _("delquote [<channel>] <num> => delete quote from <channel> with number <num>. You only need to supply <channel> if you are addressing %{nick} privately.") % { :nick => @bot.nick }
     when "getquote"
-      return "getquote [<channel>] [<num>] => get quote from <channel> with number <num>. You only need to supply <channel> if you are addressing #{@bot.nick} privately. Without <num>, a random quote will be returned. Responds to !getquote without addressing if so configured"
+      _("getquote [<channel>] [<num>] => get quote from <channel> with number <num>. You only need to supply <channel> if you are addressing %{nick} privately. Without <num>, a random quote will be returned.") % { :nick => @bot.nick }
     when "searchquote"
-      return "searchquote [<channel>] <regexp> => search for quote from <channel> that matches <regexp>. You only need to supply <channel> if you are addressing #{@bot.nick} privately. Responds to !searchquote without addressing if so configured"
+      _("searchquote [<channel>] <regexp> => search for quote from <channel> that matches <regexp>. You only need to supply <channel> if you are addressing %{nick} privately.") % { :nick => @bot.nick }
     when "topicquote"
-      return "topicquote [<channel>] [<num>] => set topic to quote from <channel> with number <num>. You only need to supply <channel> if you are addressing #{@bot.nick} privately. Without <num>, a random quote will be set. Responds to !topicquote without addressing if so configured"
+      _("topicquote [<channel>] [<num>] => set topic to quote from <channel> with number <num>. You only need to supply <channel> if you are addressing %{nick} privately. Without <num>, a random quote will be set.") % { :nick => @bot.nick }
     when "countquote"
-      return "countquote [<channel>] <regexp> => count quotes from <channel> that match <regexp>. You only need to supply <channel> if you are addressing #{@bot.nick} privately. Responds to !countquote without addressing if so configured"
+      _("countquote [<channel>] <regexp> => count quotes from <channel> that match <regexp>. You only need to supply <channel> if you are addressing %{nick} privately.") % { :nick => @bot.nick }
     when "whoquote"
-      return "whoquote [<channel>] <num> => show who added quote <num>. You only need to supply <channel> if you are addressing #{@bot.nick} privately"
+      _("whoquote [<channel>] <num> => show who added quote <num>. You only need to supply <channel> if you are addressing %{nick} privately") % { :nick => @bot.nick }
     when "whenquote"
-      return "whenquote [<channel>] <num> => show when quote <num> was added. You only need to supply <channel> if you are addressing #{@bot.nick} privately"
+      _("whenquote [<channel>] <num> => show when quote <num> was added. You only need to supply <channel> if you are addressing %{nick} privately") % { :nick => @bot.nick }
+    when "lastquote"
+      _("lastquote [<channel>] => show the last quote in a given channel. You only need to supply <channel> if you are addressing %{nick} privately") % { :nick => @bot.nick }
     else
-      return "Quote module (Quote storage and retrieval) topics: addquote, delquote, getquote, searchquote, topicquote, countquote, whoquote, whenquote"
+      _("Quote module (Quote storage and retrieval) topics: addquote, delquote, getquote, searchquote, topicquote, countquote, whoquote, whenquote, lastquote") % { :nick => @bot.nick }
     end
   end
 
@@ -155,7 +161,7 @@ class QuotePlugin < Plugin
     if delquote(channel, num)
       m.okay
     else
-      m.reply "quote not found!"
+      m.reply _("quote not found!")
     end
   end
 
@@ -242,6 +248,19 @@ class QuotePlugin < Plugin
       m.reply _("quote not found!")
     end
   end
+
+  def cmd_lastquote(m, p)
+    channel = p[:channel] || m.channel.to_s
+    quote, total = getquote(m.source, channel, lastquote(channel))
+    if quote
+      m.reply _("[%{num}] %{quote}") % {
+        :num => quote.num,
+        :quote => quote.quote
+      }
+    else
+      m.reply _("quote not found!")
+    end
+  end
 end
 
 plugin = QuotePlugin.new
@@ -258,6 +277,7 @@ plugin.map "whenquote :num", :action => :cmd_whenquote, :private => false, :requ
 plugin.map "searchquote *reg", :action => :cmd_searchquote, :private => false, :auth_path => '!quote::view::search!'
 plugin.map "countquote [*reg]", :action => :cmd_countquote, :private => false, :auth_path => '!quote::view::count!'
 plugin.map "topicquote [:num]", :action => :cmd_topicquote, :private => false, :requirements => { :num => /^\d+$/ }, :auth_path => '!quote::topic!'
+plugin.map "lastquote", :action => :cmd_lastquote, :private => false, :auth_path => '!quote::view::last!'
 
 plugin.default_auth('other::edit', false) # Prevent random people from editing other channels quote lists by default
 plugin.default_auth('other::view', true) # But allow them to view them