summaryrefslogtreecommitdiff
path: root/data/rbot/plugins
diff options
context:
space:
mode:
authorMatthias H <apoc@sixserv.org>2013-12-06 06:39:31 +0100
committerMatthias H <apoc@sixserv.org>2013-12-06 06:39:31 +0100
commitaa073ca098a00d9414b8190b3bdbd795afc8af5b (patch)
treea30e61618e5eb07ea0da72f27fe2d1cfa5313680 /data/rbot/plugins
parentbd2b1d26b59d3f5177c49141be937bee7188ec91 (diff)
url: more flexibility with first_par
Diffstat (limited to 'data/rbot/plugins')
-rw-r--r--data/rbot/plugins/url.rb25
1 files changed, 23 insertions, 2 deletions
diff --git a/data/rbot/plugins/url.rb b/data/rbot/plugins/url.rb
index 8327dd94..3faeeab9 100644
--- a/data/rbot/plugins/url.rb
+++ b/data/rbot/plugins/url.rb
@@ -27,6 +27,12 @@ class UrlPlugin < Plugin
Config.register Config::BooleanValue.new('url.first_par',
:default => false,
:desc => "Also try to get the first paragraph of a web page")
+ Config.register Config::IntegerValue.new('url.first_par_length',
+ :default => 150,
+ :desc => "The max length of the first paragraph")
+ Config.register Config::ArrayValue.new('url.first_par_whitelist',
+ :default => ['twitter.com'],
+ :desc => "List of url patterns to show the content for.")
Config.register Config::BooleanValue.new('url.info_on_list',
:default => false,
:desc => "Show link info when listing/searching for urls")
@@ -93,7 +99,6 @@ class UrlPlugin < Plugin
begin
debug "+ getting info for #{url.request_uri}"
info = @bot.filter(:htmlinfo, url)
- debug info
logopts[:htmlinfo] = info
resp = info[:headers]
@@ -101,7 +106,23 @@ class UrlPlugin < Plugin
if info[:content]
logopts[:extra] = info[:content]
- extra << "#{Bold}text#{Bold}: #{info[:content]}" if @bot.config['url.first_par']
+
+ max_length = @bot.config['url.first_par_length']
+
+ whitelist = @bot.config['url.first_par_whitelist']
+ content = nil
+ if whitelist.length > 0
+ whitelist.each do |pattern|
+ if Regexp.new(pattern, Regexp::IGNORECASE).match(url.to_s)
+ content = info[:content][0...max_length]
+ break
+ end
+ end
+ else
+ content = info[:content][0...max_length]
+ end
+
+ extra << "#{Bold}text#{Bold}: #{content}" if @bot.config['url.first_par'] and content
else
logopts[:extra] = String.new
logopts[:extra] << "Content Type: #{resp['content-type']}"