From c23c0acd01d43b452a9cf95d2e95975c566dd64d Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Fri, 10 Oct 2008 23:08:13 +0000 Subject: Add automatic URL listener code. --- gentoo-tinyurl.rb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 gentoo-tinyurl.rb (limited to 'gentoo-tinyurl.rb') diff --git a/gentoo-tinyurl.rb b/gentoo-tinyurl.rb new file mode 100644 index 0000000..5bbab71 --- /dev/null +++ b/gentoo-tinyurl.rb @@ -0,0 +1,30 @@ +require "shorturl" +class GentooShortenURLs < Plugin + def initialize + super + end + def lurk?(m) + replyto = nil + replyto = m.replyto.to_s if m.is_a?(Irc::UserMessage) + return true + return false unless replyto + end + def listen(m) + return if m.address? + return unless lurk?(m) + return unless m.message =~ /(\b|^)[a-z]+:\/\/.*($|\s)/i + m.message.split.each do |word| + next unless word =~ /(\b|^)[a-z]+:\/\/.*($|\s)/i + next unless word.length >= 32 + shrink(m, {:url => word}) + end + end + def shrink(m, params) + short = ShortURL.shorten(params[:url], :tinyurl) + m.reply short + end +end +plugin = GentooShortenURLs.new +plugin.map 't :url', + :action => 'shrink', + :auth_path => 'view' -- cgit v1.2.3-65-gdbad