Tinyurl link shortening alias

By FordLawnmower on Dec 06, 2009

This alias is designed to be used from inside a script. It will replace ALL the links in the argument you send it and return them with whatever method you want.

For Instance:
If you have a script that is returning some long crazy links, go to the portion of the script that messages the channel and put Shrinklinks in front of that line.

Lets say the message line is this.
msg #channelname Here is your crazy link - %crazylink
You would just change this to
ShrinkLinks msg #channelname Here is your crazy link - %crazylink

This will work with msg channel - msg nick - notice nick - or echo -anyvalidoptions
It will also work with the optional dot(.) , as in .msg

Example Input and Output:
Input:
/shrinklinks echo -a The other day I googled new york with http://google.com I didn't have much luck so I used http://yahoo.com . I ended up using http://wikipedia.com

Output:
The other day I googled new york with http://tinyurl.com/2tx I didn't have much luck so I used http://tinyurl.com/2ks . I ended up using http://tinyurl.com/4sgkr

Input:
/shrinklinks echo -a Hello world

Output:
Hello world

;shrinklinks by Ford_Lawnmower irc.geekshed.net -j #Script-Help
alias -l shrinklinks {
  if ($wildtok($strip($4-),http://*.*,0,32) == $wildtok($strip($4-),http://tinyurl.com*,0,32)) { 
    $eval($1-,1)
    return
  }
  var %count $wildtok($strip($4-),http://*.*,0,32), %text $strip($4-)
  while %count {
    if ($left($wildtok(%text,http://*.*,%count,32),18) != http://tinyurl.com) {
      tiny $1-3 $wildtok(%text,http://*.*,%count,32) $4-
      %count = 0
      return 
    }
    dec %count
  }
}
alias -l Tiny {
  var %sockname $+(Tiny,$network,$ticks,$r(1,$ticks))
  sockopen %sockname tinyurl.com 80
  sockmark %sockname $1-3 $+(/create.php?url=,$urlencode($4)) $4 $5-
}
On *:sockopen:Tiny*: {
  if (!$sockerr) {
    sockwrite -nt $sockname GET $gettok($sock($sockname).mark,4,32) HTTP/1.0
    sockwrite -n $sockname Host: tinyurl.com
    sockwrite -n $sockname $crlf
  }
  else { echo -st Socket Error $nopath($script) | sockclose $sockname | return }
}
On *:sockread:Tiny*: {
  if ($sockerr) { echo -st Socket Error $nopath($script) | sockclose $sockname | return }
  else {
    var %Tiny | sockread %Tiny
    if ($regex(%Tiny,/<blockquote><b>(.*)<\/b><br><small>/i)) {
      tokenize 32 $sock($sockname).mark
      shrinklinks $1-3 $replace($6-,$5,$remove($regml(1),preview.))
      sockclose $sockname
      return
    }
  }
}
alias -l urlencode return $regsubex($1-,/([^a-z0-9])/ig,% $+ $base($asc(\t),10,16,2))

Comments

Sign in to comment.
Lloyd76   -  Oct 06, 2016

And what for should they be used? Sometimes, I see that twitter doesn't let me post my links.

 Respond  
Lloyd76   -  Oct 06, 2016

I've never used these. What about ow.ly and bit.ly? I hear they work well too.

 Respond  
ovelayer   -  Oct 02, 2015

stopped working any chance for an update? please ty ty

ProIcons  -  Oct 02, 2015

Change line 34.

if ($regex(%Tiny,/<blockquote><b>(.*)<\/b><br><small>/i)) {

to

 if ($regex(%Tiny,/<div class=\"indent\"><b>(.*)<\/b>/i)) {
ovelayer  -  Oct 03, 2015

AWSOME ty Prolcons!!

Sign in to comment

ProIcons   -  Jun 22, 2013
 Respond  
FordLawnmower   -  Jun 17, 2013

Updated

 Respond  
ovelayer   -  Apr 17, 2013

is there anyway to get this to work with magnet links? i tried but FaiL

 Respond  
ovelayer   -  Mar 09, 2013

this is what i have come up with
http://pastebin.com/QMNRn7FR
so far i can get it to work in the @window but i cant get it to work when it msg's the channel... =(

 Respond  
ovelayer   -  Mar 09, 2013

thank you for answering my email ford..
when i try to use this with the news tracker script
i get this error
-NT Unknown command
thanks for your time!

FordLawnmower  -  Mar 09, 2013

pastebin the code for me, as it is now and I will look at it.

ovelayer  -  Mar 09, 2013
FordLawnmower  -  Mar 09, 2013

Sorry , I wanted the script with the tinyurl script added so I can see where the error is coming from.

ovelayer  -  Mar 09, 2013

ah well i found out i was getting the nt error because i did not add your alias to the actual script was trying to add it under the alias tab..
but i added to the script and placed the shrinklinks infront of the msg parts but i still cant seem to get it working
here is what i have done
http://pastebin.com/1sHMhpKe

FordLawnmower  -  Mar 09, 2013

It looks fine. I just updated the code to what I'm using. Please try that and let me know : http://www.hawkee.com/snippet/7005/

fungi  -  Jun 14, 2013

I'm new to mIRC scripts. I added this script to Aliases and Remote. However, repeating the /shrinklinks command with the parameters you specified gave me nothing (Shrinklinks unknown command). I tried many other scripts and failed every time. What am I missing?

FordLawnmower  -  Jun 14, 2013

@fungi This alias is designed to be placed in the script you want to use it in, so it's a local alias.
If you want to call the alias from outside the snippet, just change line 2 from :

alias -l shrinklinks {

To:

alias shrinklinks {
fungi  -  Jun 15, 2013

FordLawnMower,
I tried almost a dozen variations, loading it in remote, aliases, restarting mIRC and trying the code suggestions. Maybe I'm not using it right: I copied the code above, removed " -l" on line 2 and typed "/shrinklinks http://www.google.com" in the channel I was in. It still didn't return a tinyurl. Is this script indeed supposed to shorten urls while in chat, or was it maybe designed for other purposes and I'm just understanding/using it wrong?

FordLawnmower  -  Jun 16, 2013

@fungi You're not following the instructions.

Lets say the message line is this.
msg #channelname Here is your crazy link - %crazylink
You would just change this to
ShrinkLinks msg #channelname Here is your crazy link - %crazylink

You have to send the ShrinkLinks alias output information in the first two tokens.
This is made to use inside a script , but it is possible to use this in normal chat.
Example:

//shrinklinks msg # Check out this link http://www.google.com

Both slashes are needed for this to work //shrinklinks , not /shrinklinks.

You could also add a alias to the end of the script.
Just hit ctrl+end to get to the bottom of the script.
Press [enter] to add a new line.
And paste in this alias.

alias tinysend { shrinklinks msg # $$1- }

Then just save the script.

You will now be able to type /tinysend message containing links here.

If you still need help , come to irc.geekshed.net #Script-Help

FordLawnmower  -  Jun 17, 2013

@fungi This snippet was actually broken. It's updated and working again.

Sign in to comment

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.