The code I gave you already does this.
Anyway, for further queries others will have to help you, I've done my part, hopefully you can figure out the rest. There could be some more changes to the code to build some sort of flood protection, so that no one can go crazy and ask for 10 url's in 1 second etc, and various little tweaks to make it more fullproof (check if you are still on the channel before messaging it, check if you are still connected to a server before messaging $nick etc. etc.), but others can do that if they want.
Btw you could check $sock($sockname).wserr for a more accurate error code, but for your purposes $sockerr will suffice.