User:Jacnoc/ShortURL/BitLy

Script Purpose
This script was written for when someone posts a(n) http://bit.ly link. When such link is posted, the script will trigger and reveal the location that the short url leads to. Useful because some people link to use URL shortening services to link to inappropriate websites (pornography, shock sites, etc...)

CODE

 * Written by Joshua
 * Date: Either 2009 or 2010
 * I give permission for this script to be used, and altered (example: altering the appearance of the output sentence)
 * Altering the script is not recommended if you do not know what you are doing as it could result in the script no longer working! (Of course if that happens, feel free to copy the code from the page for the working copy of the script).
 * Changing variables is not recommended as it could cause the script to break. Consider this your official warning. I take no responsibility if the script ceases to function after you have changed it. (I also take no responsibility if the script ceases to function due to bit.ly changing their page.
 * Please leave the above comments in tact for legal use of this script! Thanks!

on *:TEXT:*:#: { if ($regex($1-,/((?:http?:\/\/)?(?:www|w3|web|forums?|tinyurl|bit).+)/Si)) { if (http://bit.ly isin $regml(1)) { set %original $1- set %id $gettok($1-,3,47) set %nick $nick var %sckid $right($ticks,5) set %way. [ $+ [ %sckid ] ] echo -ga $chan sockopen bitly. [ $+ [ %sckid ] ] bit.ly 80 } } } on *:SOCKOPEN:bitly.*: { sockwrite -nt $sockname GET / $+ %id HTTP/1.1 sockwrite -nt $sockname Host: bit.ly sockwrite -nt $sockname $crlf } on *:SOCKREAD:bitly.*: { if ($sockerr) { echo -sg Socket Error: $sockname $+. Error code: $sockerr. halt } else { var %sockreader sockread %sockreader if (*Location:* iswm %sockreader) { noop $regex(%sockreader,/Location:(.*?)$/Si) var %tempvar $regml(1) %way. [ $+ [ $right($sockname,5) ] ] $str($chr(160),5) $+($chr(151),$chr(155)) %original redirects to: %tempvar unset %*. [ $+ [ $right($sockname,5) ] ] unset %nick unset %id unset %original sockclose $sockname } } }

Install/How-To
Follow the following steps to install/use the script.

[16:19:42] <@Jacnoc> http://bit.ly/test
 * 1) Copy the code (select/highlight the code and press CTRL+C to copy).
 * 2) Open the mIRC Script Editor. Shortcut: Press ALT+R.
 * 3) Paste the script into the script editor (recommmendation: press CTRL+V).
 * 4) Save the file (Go to File -> Save As...)
 * 5) * Recommended filename:
 * 6) Enjoy the results when someone posts a(n) http://bit.ly/ link.
 * 7) * Example:


 * —› http://bit.ly/test redirects to: http://en.wikipedia.org/wiki/Chris_Messina_(open_source_advocate)

Copyright/Info
This script was written by Joshua (Freenode IRC nick: Jacnoc and Wiki username Jacnoc). Date: Unknown (most likely 2010. Although 2009 is a possibility). You have permission to use this script. Permission is given to edit the script (example to alter the appearance of the output to make it show in the channel the way you want).