summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2008-03-19 14:45:59 +0100
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2008-03-19 14:49:49 +0100
commit9a98a241d33d405bb104d27357af64afd4d5e6b2 (patch)
tree1e8a35bc4c5c04e2b16fca212686dd4b0b25ef3d
parentfce8443bb6ab99c3b36fc95583bb59275f019251 (diff)
freshmeat plugin: htmlinfo filter
-rw-r--r--data/rbot/plugins/freshmeat.rb36
1 files changed, 35 insertions, 1 deletions
diff --git a/data/rbot/plugins/freshmeat.rb b/data/rbot/plugins/freshmeat.rb
index 49e73e0d..494cfb48 100644
--- a/data/rbot/plugins/freshmeat.rb
+++ b/data/rbot/plugins/freshmeat.rb
@@ -1,3 +1,8 @@
+#-- vim:sw=2:et
+#++
+#
+# :title: Freshmeat plugin for rbot
+
require 'rexml/document'
class FreshmeatPlugin < Plugin
@@ -5,7 +10,36 @@ class FreshmeatPlugin < Plugin
def help(plugin, topic="")
"freshmeat search [<max>=4] <string> => search freshmeat for <string>, freshmeat [<max>=4] => return up to <max> freshmeat headlines"
end
-
+
+ REL_ENTRY = %r{<a href="/(release)s/(\d+)/"><font color="#000000">(.*?)</font></a>}
+ PRJ_ENTRY = %r{<a href="/(project)s/(\S+?)/"><b>(.*?)</b></a>}
+
+ # This method defines a filter for fm pages. It's needed because the generic
+ # summarization grabs a comment, not the actual article.
+ #
+ def freshmeat_filter(s)
+ loc = Utils.check_location(s, /freshmeat\.net/)
+ return nil unless loc
+ entries = []
+ s[:text].scan(/#{REL_ENTRY}|#{PRJ_ENTRY}/) { |m|
+ entry = {
+ :type => ($1 || $4).dup,
+ :code => ($2 || $5).dup,
+ :name => ($3 || $6).dup
+ }
+ entries << entry
+ }
+ return nil if entries.empty?
+ title = s[:text].ircify_html_title
+ content = entries.inject([]) { |l, e| l << e[:name] }.join(" | ")
+ return {:title => title, :content => content}
+ end
+
+ def initialize
+ super
+ @bot.register_filter(:freshmeat, :htmlinfo) { |s| freshmeat_filter(s) }
+ end
+
def search_freshmeat(m, params)
max = params[:limit].to_i
search = params[:search].to_s