napa182 commented on a Page, Tuly URL Shortner  -  Oct 20, 2010

you could do it like this so you can do away with the global vars..

on $*:text:/^@url\s(http\x3A\/\/w{3}\x2E\S+\x2E\S{2,3}?\S+)/iS:#:{
  if ($sock(tuly)) sockclose tuly
  sockopen tuly www.tuly.in 80 
  sockmark tuly $+(/bm.php?url=,$regml(1)) msg # Shortened URL:
}
on *:sockopen:tuly: {
  sockwrite -n tuly GET $gettok($sock(tuly).mark,1,32) HTTP/1.1
  sockwrite -n tuly Host: $+($sock(tuly).addr,$str($crlf,2))
}
on *:sockread:tuly: {
  var %tuly | sockRead %tuly
  if ($regex(%tuly,/(http:\/\/.+)/)) { 
    $gettok($sock(tuly).mark,2-,32) $regml(1)
    sockclose tuly
  }
}

output is the same as the one you posted

Shortened URL: http://tuly.in/lYmBjY

you can also use the post method

on $*:text:/^@tuly\s(http\x3A\/\/w{3}\x2E\S+\x2E\S{2,3}?\S+)/iS:#:{  
  if ($sock(tuly)) sockclose tuly
  sockopen tuly tuly.in 80 
  sockmark tuly $regml(1) msg # Shortened URL:
}
on *:sockopen:tuly:{ 
  var %tuly $+(url=,$gettok($sock(tuly).mark,1,32),&submit=Shorten)
  sockwrite -n tuly POST /process.php HTTP/1.1 
  sockwrite -n tuly Host: $sock(tuly).addr 
  sockwrite -n tuly Content-Type: application/x-www-form-urlencoded 
  sockwrite -n tuly Content-Length: $len(%tuly) 
  sockwrite -n tuly $+($crlf,%tuly)
}
on *:sockread:tuly: { 
  var %tuly | sockread %tuly
  if ($regex(%tuly,/<.+value='(http.+?)'><\/h2>/)) { 
    $gettok($sock(tuly).mark,2-,32) $regml(1)
  }
}

the output looks like this

Shortened URL: http://tuly.in/lLwNaW

 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.