This is a simple URL shortener designed to be used on an mIRC bot.
It simply shortens any url entered using ur.cx, and messages it to the channel.
Feel free to ask any questions... irc.infinityirc.com #infinity
Have fun
NB: Thanks to Jethro_ for improvements.
on *:sockread:lop:{
var %read | sockread %read | if http:// isin %read {
.msg $gettok($sock(lop).mark,1,32) Shortened URL: $v2
}
}
on $*:text:/^!url\s((\w{3,8}\72\/\/)?(w{3}\56.+|\w+(?=\.\w{2,6})))/iS:#:{
if !%tc { inc -u4 %tc | if $sock(lop) { sockclose lop }
sockopen lop ur.cx 80 | sockmark lop $chan $regml(1)
}
}
on *:sockopen:lop:{
var %sockmark $gettok($sock(lop).mark,2,32)
sockwrite -n lop GET $+(/api/create.php?url=,%sockmark) HTTP/1.1
sockwrite -n lop Host: ur.cx $+ $str($crlf,2)
}
Still no luck I'm afraid.
I can't see any errors in the status window, the bot just wont respond.
This is very odd, I can't figure out why it won't work.
If I get a chance later I'll try it on another of my PCs. I'm running mIRC 6.35 at the moment so it should really be fine.
I've even gone through and deleted any other scripts that use the same socket name, or similar scripts, but still no luck.
Below is the update from the one I made on June 13th last year, and it's been tested and working for me:
on *:sockread:lop:{
var %read | sockread %read | if http:// isin %read {
.msg $gettok($sock(lop).mark,1,32) Shortened URL: $v2
}
}
on $*:text:/^!url\s((\w{3,8}\72\/\/)?(w{3}\56.+|\w+(?=\.\w{2,6})))/iS:#:{
if !%tc { inc -u4 %tc | if $sock(lop) { sockclose lop }
sockopen lop www.l0p.us 80 | sockmark lop $chan $regml(1)
}
}
on *:sockopen:lop:{
var %sockmark $gettok($sock(lop).mark,2,32)
sockwrite -n lop GET $+(/api-make.php?alias=&url=,%sockmark) HTTP/1.1
sockwrite -n lop Host: www.l0p.us $+ $str($crlf,2)
}
I'm not sure why you'd say it does not work for you. The only thing I can think of is the $v2 identifier not being recognized by your mIRC. You're perhaps running an old version below 6.16. If that's the case, you need to replace it with: $ifmatch2
That said, if my other version made on Nov. 14th, 2010 that's worked for the above poster HeartbrokenTR, I don't see the reason it should fail on you.
P.S. Place my version in a new remote or temporarily replace yours with mine. Since they both share the same trigger, it might have been causing the conflict.
Henco, my example above doesn't require the !url command. You simply enter a URL to have it return with a shortened one.> www.blah.com
Shortened URL for "www.blah.com" is: http://l0p.us/hum http://www.blah.net Shortened URL for "http://www.blah.net" is: http://l0p.us/ttjNot only my example covers the text, it also triggers on action and notice. In addition, you need to enter an address starting with either http:// or www. I didn't make it to trigger on "example.com"Jethro_, I'm gonna update this script to use a better url shortener, and I was gonna use your updated version but I can't get it to work.
The one I originally posted still seems to work fine, but I tried loading your updated one and it just seems to do nothing. I tried:
[17:45] <~Henco> !url example
[17:46] <~Henco> !url example.com
[17:46] <~Henco> !url http://example.com
[17:46] <~Henco> !url http://example.com/
[17:46] <~Henco> !url http://example.com/
None did anything, unfortunately.
Any help would be much appreciated.
Cheers,
Henco
HeartBrokenTR, here is the code edited to be automated in detecting any URL entered in the channel and have it converted as a shortened version:
on *:text:*:#:lop $1-
on *:action:*:#:lop $1-
on *:notice:*:#:lop $1-
alias -l lop {
if !%tc {
inc -u4 %tc
if $sock(lop) { sockclose lop }
if $regex($1-,/((\w{3,8}\72\/\/)?(w{3}\56.+|\w+(?=\.\w{2,6})))/iS) {
sockopen lop www.l0p.us 80
sockmark lop # $regml(1)
}
}
}
on *:sockopen:lop:{
if $sockerr {
.msg $token($sock(lop).mark,2,32) * ERROR: $sock(lop).wsmsg
}
else {
var %sockmark $token($sock(lop).mark,2,32), %lop sockwrite -n lop
%lop GET $+(/api-make.php?alias=&url=,%sockmark) HTTP/1.1
%lop Host: www.l0p.us $+ $str($crlf,2)
}
}
on *:sockread:lop:{
var %read, %x $token($sock(lop).mark,1,32), %y $token($sock(lop).mark,2,32)
sockread %read
if http:// isin %read {
.msg %x Shortened URL for $+(",%y,") is: $v2
}
}
It'll also work for text, action and notice.
Henco, nice work. I agree with Gummo and Sean that you should have used the sockmark command instead of the global var. There are a couple of overlooked considerations:
1) Make sure the $2 entered is a URL, not something else.
2) you should add a trigger protection to it to safeguard the client running the code to not get flooded.
Here is the improved version of your script:
on $*:text:/^!url\s((\w{3,8}\72\/\/)?(w{3}\56.+))/iS:#:{
if !%tc { inc -u4 %tc | if $sock(lop) { sockclose lop }
sockopen lop www.l0p.us 80 | sockmark lop $chan $regml(1) }
}
on *:sockopen:lop:{
var %sockmark $gettok($sock(lop).mark,2,32)
sockwrite -n lop GET $+(/api-make.php?alias=&url=,%sockmark) HTTP/1.1
sockwrite -n lop Host: www.l0p.us $+ $str($crlf,2)
}
on *:sockread:lop:{
var %read | sockread %read
if http:// isin %read { .msg $gettok($sock(lop).mark,1,32) Shortened URL: $v2 }
}
great snippet. i would sockmark the chan and url info instead of setting global vars though. if multiple users request a !url around the same time, one could override another user's information causing incorrect data to be displayed. sockmark'ing the info would prevent that from happening - and you wouldn't need to unset info as it would die along with the sockclose
rated 6/10 for neat