AutoMagic URL Shorten-er™ (using goo.gl)

By TheImrac on May 01, 2012

Made a quick script to automatically shorten URLs on input.

I used Fuzionx usage of Chessnut's $getsource script.

Here is a link to Fuzionx: http://www.hawkee.com/snippet/8312/
And Chessnut's $getsource script http://forum.swiftirc.net/viewtopic.php?f=74&t=24161

This uses COMs so you must have them enabled. The script should be pretty dang quick even with multiple URLs in a single message.

You can turn it off by right clicking the channel or query window, or you can use an exclamation point in front of your message.

Let me know if anyone has issues with URL's not being caught or if other things are accidentally caught.

; Version 1.0.2
; Fixed regex color stripper

; Version 1.0.1
; - Fixed regex boo-boo

;Version 1.0.0
; - Initial Release

; // Our alias that attempts to shorten and return the URL past  //
; // based on Fuzionx "URL Shortern" Script (hawkee) //
; // Also Based on Chessnuts $getsource script (unknown) //
alias goo.gl {
  var %longURL = $1
  var %com.name = shorten. $+ $ticks
  .comopen %com.name msxml2.xmlhttp
  noop $com(%com.name,OPEN,1,bstr,POST,bstr,https://www.googleapis.com/urlshortener/v1/url $+ $iif($goo.gl_api,?key= $+ $v1),bool,false)
  noop $com(%com.name,setRequestHeader,1,bstr,Content-Type,bstr,application/json)
  noop $com(%com.name,Send,1,bstr,$+($chr(123),"longUrl": $qt(%longURL),$chr(125)))
  noop $com(%com.name,ResponseText,2)
  var %fullresult = $com(%com.name).result
  .comclose %com.name
  if ($regex(%fullresult,/"id": "(.*?)"/)) { return $regml(1) }
  else {
    echo -q 5 Goo.gl: An Error occured while shorting $1
    return %longURL
  }
}
alias -l goo.gl_api { return AIzaSyDMl5272dQj965CkWUqlqZBnTFWMW9BiE0 }

; // Helper Aliases to catch and attempt to shorten input url  //
alias -l url-regex { return /(?<=^| )((?:(?:ht|f)tps?:[/][/])?(?:www\.|[\w\d\.]+\.|(?=[\w\d]+\.(?:com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum|travel|tv|co|tk)))[\w\d]+\.[\w]{2,3}(?:[/]\S*)?)/giS }
alias short.input {
  if (!$regex($1-,/^[/!]/s)) {
    say $regsubex(url,$1-,$url-regex,$goo.gl( \t ))
    halt
  }
}

menu channel,query {
  Auto URL Short
  .On:.enable #shortener
  .Off:.disable #shortener
}

; // And of course our input events //
#shortener on
on *:input:?:{ short.input $1- }
on *:input:#:{ short.input $1- }
#shortener end

Comments

Sign in to comment.
dma   -  May 17, 2015

this goes in remote?

 Respond  
chorao   -  Nov 30, 2012

Using... :)

 Respond  
TheImrac   -  May 02, 2012

Nice find!! Thanks!

 Respond  
Firstmate   -  May 02, 2012

This is where I remember seeing his script a long time ago.
$getsource: http://forum.swiftirc.net/viewtopic.php?f=74&t=24161

Nice script by the way.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.