diff options
author | Yaohan Chen <hagabaka@nanomachine.STUDENT.cwru.edu> | 2008-03-21 10:47:30 -0400 |
---|---|---|
committer | Yaohan Chen <hagabaka@nanomachine.STUDENT.cwru.edu> | 2008-03-21 10:47:30 -0400 |
commit | fdf1bc954352f19818f5f9f1c86643a2f8ef40c6 (patch) | |
tree | 5133ca5713af2b4aa756ad6c63a46db3fe141e66 /data | |
parent | 2181f8f40f6dfc1ca7e48d82c0dfdcde6436ce72 (diff) | |
parent | 9a98a241d33d405bb104d27357af64afd4d5e6b2 (diff) |
Merge branch 'master' of ssh://ruby-rbot.org/var/git/rbot
Diffstat (limited to 'data')
-rw-r--r-- | data/rbot/plugins/freshmeat.rb | 36 | ||||
-rw-r--r-- | data/rbot/plugins/imdb.rb | 39 | ||||
-rw-r--r-- | data/rbot/plugins/script.rb | 42 | ||||
-rw-r--r-- | data/rbot/plugins/slashdot.rb | 39 |
4 files changed, 132 insertions, 24 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 diff --git a/data/rbot/plugins/imdb.rb b/data/rbot/plugins/imdb.rb index 84d0bb17..2fde6cb1 100644 --- a/data/rbot/plugins/imdb.rb +++ b/data/rbot/plugins/imdb.rb @@ -153,13 +153,13 @@ class Imdb country = data.ircify_html.gsub(' / ','/') end - info << [title, "(#{country}, #{date})", extra, dir ? "[#{dir}]" : nil, ": http://us.imdb.com#{sr}"].compact.join(" ") + info << [title, "(#{country}, #{date})", extra, dir ? "[#{dir}]" : nil, opts[:nourl] ? nil : ": http://www.imdb.com#{sr}"].compact.join(" ") return info if opts[:title_only] if opts[:characters] info << resp.body.scan(CREDIT_NAME_MATCH).map { |url, name, role| - "%s: %s" % [name, role] + "%s: %s" % [name, role.ircify_html] }.join('; ') return info end @@ -205,7 +205,8 @@ class Imdb return nil if !m name = m[1] - info << "#{name} : http://us.imdb.com#{sr}" + info << "#{name}" + info << " : http://www.imdb.com#{sr}" unless opts[:nourl] return info if opts[:name_only] @@ -405,9 +406,41 @@ class ImdbPlugin < Plugin attr_reader :i + TITLE_URL = %r{^http://(?:[^.]+\.)?imdb.com(/title/tt\d+/)} + NAME_URL = %r{^http://(?:[^.]+\.)?imdb.com(/name/nm\d+/)} + def imdb_filter(s) + loc = Utils.check_location(s, TITLE_URL) + if loc + sr = loc.first.match(TITLE_URL)[1] + extra = $2 # nothign for the time being, could be fullcredits or whatever + res = i.info_title(sr, :nourl => true, :characters => (extra == 'fullcredits')) + debug res + if res + return {:title => res.first, :content => res.last} + else + return nil + end + end + loc = Utils.check_location(s, NAME_URL) + if loc + sr = loc.first.match(NAME_URL)[1] + extra = $2 # nothing for the time being, could be filmoyear or whatever + res = i.info_name(sr, :nourl => true, :movies_by_year => (extra == 'filmoyear')) + debug res + if res + name = res.shift + return {:title => name, :content => res.join(". ")} + else + return nil + end + end + return nil + end + def initialize super @i = Imdb.new(@bot) + @bot.register_filter(:imdb, :htmlinfo) { |s| imdb_filter(s) } end # Find a person or movie on IMDB. A :type (name/title, default both) can be diff --git a/data/rbot/plugins/script.rb b/data/rbot/plugins/script.rb index 5e2f1e58..c994d4da 100644 --- a/data/rbot/plugins/script.rb +++ b/data/rbot/plugins/script.rb @@ -70,29 +70,31 @@ class ScriptPlugin < Plugin def handle_eval( m, params ) code = params[:code].to_s.dup.untaint - Thread.start { - # TODO allow different safe levels for different botusers - begin - eval( code ) - rescue Exception => e - m.reply( "Script '#{name}' crapped out :(" ) - m.reply( e.inspect ) - end - } + Thread.start { + # TODO allow different safe levels for different botusers + begin + eval( code ) + rescue Exception => e + m.reply( "Script '#{name}' crapped out :(" ) + m.reply( e.inspect ) + end + } + m.replied = true end def handle_echo( m, params ) code = params[:code].to_s.dup.untaint - Thread.start { - # TODO allow different safe levels for different botusers - begin - m.reply eval( code ).to_s - rescue Exception => e - m.reply( "Script '#{name}' crapped out :(" ) - m.reply( e.inspect ) - end - } + Thread.start { + # TODO allow different safe levels for different botusers + begin + m.reply eval( code ).to_s + rescue Exception => e + m.reply( "Script '#{name}' crapped out :(" ) + m.reply( e.inspect ) + end + } + m.replied = true end @@ -111,7 +113,7 @@ class ScriptPlugin < Plugin command = Command.new( code, nick, created, channel ) @commands[name] = command - m.reply( "done" ) + m.okay end @@ -127,7 +129,7 @@ class ScriptPlugin < Plugin end @commands.delete( name ) - m.reply( "done" ) + m.okay end diff --git a/data/rbot/plugins/slashdot.rb b/data/rbot/plugins/slashdot.rb index c9e35b9e..b02a5a25 100644 --- a/data/rbot/plugins/slashdot.rb +++ b/data/rbot/plugins/slashdot.rb @@ -1,3 +1,8 @@ +#-- vim:sw=2:et +#++ +# +# :title: Slashdot plugin for rbot + require 'rexml/document' class SlashdotPlugin < Plugin @@ -5,6 +10,40 @@ class SlashdotPlugin < Plugin def help(plugin, topic="") "slashdot search <string> [<max>=4] => search slashdot for <string>, slashdot [<max>=4] => return up to <max> slashdot headlines (use negative max to return that many headlines, but all on one line.)" end + + # This method defines a filter for /. pages. It's needed because the generic + # summarization grabs a comment, not the actual article. + # + # This filter relies on Hpricot being available, since REXML isn't too + # happy with the /. pages + def slashdot_filter(s) + return nil unless defined? Hpricot + loc = Utils.check_location(s, /slashdot\.org/) + return nil unless loc + h = Hpricot(s[:text]) + title = (h/"head/title").first.to_html.ircify_html + arts = (h/"div.article") + if arts.length > 1 + tits = [] + arts.each { |el| + artitle = (el/"div.generaltitle").first.to_html.ircify_html + tits << artitle + } + content = tits.join(" | ") + else + det = (arts.first/"div.details").first.to_html.ircify_html + body = (arts.first/"div.body").first.to_html.ircify_html + content = [det, body].join(' ') + end + return {:title => title, :content => content} + end + + def initialize + super + if defined? Hpricot + @bot.register_filter(:slashdot, :htmlinfo) { |s| slashdot_filter(s) } + end + end def search_slashdot(m, params) max = params[:limit].to_i |