TinyURL converter

By Lindrian on Mar 30, 2008

This is a simple TinyURL converter. Simply type /tinyurl
or //echo -a $tinyurl(url)

You can also type [.!@]tiny or [.!@]tinyurl in a channel to output the information.

Thanks to Chess for showing the COM usage.

Hope you'll enjoy it! ;)

alias tinyurl {
  var %c $iif($isid,return,echo -a)
  if ($1) && (!$com(u)) && (!$sock(tinyurl)) {
    if ($regex($1,/^(?:(?:f|ht)tps?:\/\/|[^<>\/:\s])+[^<>.:\/\s]+(?:\.[^\/:<>.\s]{2,6})+(?:\/.*?)?$/i)) {
      sockopen tinyurl www.tinyurl.com 80
      sockmark tinyurl /create.php?url= $+ $remove($1-,$chr(32))
      .comopen u Wscript.Shell
      .comclose u $com(u,run,1,bstr*,$(%comspec%,) /c ping.exe -n 2 127.0.0.1 >nul,uint,0,bool,true)
      %c $iif(%tinyurl,$v1,No result.) 
    }
    else %c Invalid URL!
  }
  else %c $iif($1,Please be patient...,Input a URL!)
}
on *:sockopen:tinyurl: {
  if ($sockerr) {
    set -u3 %tinyurl Error connecting: $sock($sockname).wsmsg
    sockclose $sockname
  }
  else {
    sockwrite -n $sockname GET $sock($sockname).mark HTTP/1.1
    sockwrite -n $sockname Host: tinyurl.com
    sockwrite -n $sockname User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8)
    sockwrite -n $sockname $crlf
  }
}
on *:sockread:tinyurl: {
  if ($sockerr) {
    set -u3 %tinyurl Error connecting: $sock($sockname).wsmsg
    sockclose $sockname
  }
  else {
    var %x
    sockread %x
    if ($regex(%x,/<blockquote><b>(.*?)<\/b><br>/)) {
      set -u3 %tinyurl $regml(1)
      sockclose $sockname
    }
  }
}
on $*:TEXT:/^[.!@]tiny(url)? .*?$/Si:#: {
  if (!%tinyurl. [ $+ [ $2 ] ]) {
    var %c = $tinyurl($2) 
    msg $chan $iif(error !isin %c && invalid !isin %c,TinyURL converted: %c $+([,From $len($2) to $len(%c) chars,]),%c)
    set -u5 %tinyurl. $+ $2 1
  }
}

Comments

Sign in to comment.
Korvin   -  Feb 12, 2009

yes.

on $*:TEXT:/^(?:(?:f|ht)tps?:\/\/|[^<>\/:\s])+[^<>.:\/\s]+(?:\.[^\/:<>.\s]{2,6})+(?:\/.*?)?$/Si:#: {
  if (!%tinyurl. [ $+ [ $2 ] ]) {
    var %c = $tinyurl($2) 
    msg $chan $iif(error !isin %c && invalid !isin %c,TinyURL converted: %c $+([,From $len($2) to $len(%c) chars,]),%c)
    set -u5 %tinyurl. $+ $2 1
  }
}
 Respond  
SuPeRFlY   -  Aug 26, 2008

Is there a way to make thit do it automatic? EXAMPLE: you type http://blah.blah.blah.com
and your addon automaticaly makes it http://tinyurl.com/5noqt3 or what ever. Instead of doing !tiny

 Respond  
Lindrian   -  Apr 03, 2008

Only I who found the identifier feature ($tiny() and $tinyurl() that is) useful?

 Respond  
Lindrian   -  Mar 30, 2008

Thanks to both of you :)

Updated the script, added a \"advanced\" URL validation, please test it out for me and tell me where it fails etc :)

 Respond  
giggle-tan   -  Mar 30, 2008

noice, works perfect :D

 Respond  
Hawkee   -  Mar 30, 2008

Neat Lind.

 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.