summaryrefslogtreecommitdiff
path: root/data
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2006-10-23 22:27:53 +0000
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2006-10-23 22:27:53 +0000
commitb1fdcc531e5d13087b58efd6036b75bf32da6931 (patch)
treeba53535727a511dec8b2b26e9e5ab4d283d559e3 /data
parent49ec18f1be46c3ed9e9838ff7b3f9a3e1fc43456 (diff)
Make rubyurl more strict about URLs to be shortened
Diffstat (limited to 'data')
-rw-r--r--data/rbot/plugins/rubyurl.rb36
1 files changed, 17 insertions, 19 deletions
diff --git a/data/rbot/plugins/rubyurl.rb b/data/rbot/plugins/rubyurl.rb
index 89a2cc4b..96e78b92 100644
--- a/data/rbot/plugins/rubyurl.rb
+++ b/data/rbot/plugins/rubyurl.rb
@@ -1,4 +1,5 @@
require "shorturl"
+require "uri"
class RubyURL < Plugin
@@ -7,32 +8,29 @@ class RubyURL < Plugin
return "rubyurl <your long url>"
end
- # reply to a private message that we've registered for
- def privmsg(m)
-
- # m.params contains the rest of the message, m.plugin contains the first
- # word (useful because it's possible to register for multiple commands)
- unless(m.params)
- m.reply "incorrect usage. " + help(m.plugin)
+ def shorten(m, params)
+ if (params[:url] == "help")
+ m.reply help(m.plugin)
+ return
end
- # TODO: might want to add a check here to validate the url
- # if they call 'rubyurl help' backwards, don't return a lame link
-
- if (m.params == "help")
- m.reply "Try again. Correct usage is: " + help(m.plugin)
- return false
+ url = params[:url]
+ begin
+ to_uri = URI.parse(url)
+ # We don't accept 'generic' URLs because almost everything gets in there
+ raise URI::InvalidURIError if to_uri.class == URI::Generic
+ rescue URI::InvalidURIError
+ m.reply "#{url} doesn't look like an URL to me ..."
+ return
end
- # call the ShortURL library with the value of the url
- url = ShortURL.shorten(m.params)
-
-
- m.reply "Your RubyURL: #{url}"
+ short = WWW::ShortURL.shorten(url)
+ m.reply "#{url} shortened to #{short} on RubyURL"
end
+
end
# create an instance of the RubyURL class and register it as a plugin
rubyurl = RubyURL.new
-rubyurl.register("rubyurl")
+rubyurl.map "rubyurl :url", :action => 'shorten'