Image Script

By Zerg on Aug 11, 2009

A script that if you click on a link( If your on mIRC ) it will open the picture in a @window

or

if your on a different chat client, and you see your bot (or other nickname) type .i

Triggers:
Click on rollover

.i

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Zerg's Image Script ---------------;;
;;Coded By Zerg----------------------;;
;;Contact on: Irc.swiftirc.net 6667--;;
;;#zergs_list #fender or #gs-pure----;;
;;All rights reserved.---------------;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

/* 
Check Cache Directory 
Make and Load Hash Table 
*/ 
alias getimage { 
  if (!$regex($1,/\b\Qhttp://\E[^\.\s]+\.[^\s]+\.(?:png|jpe?g|bmp|gif)\b/Si)) $hget(GetImage,erroralias) You need to specify a valid image url 
  if ($window(@display)) { 
    window -c @display 
    var %a $remove($1,http://),%b $gettok(%a,1,47),%d $remove(%a,%b) 
    if (!$isdir(images)) mkdir images 
    if (!$sock(getimage)) { 
      sockopen getimage %b 80 
      sockmark getimage %b %d 
    } 
  } 
  elseif ($sock(getimage*)) { 
    $hget(GetImage,erroralias) A picture is already loading, please wait until it has finished loading. 
    halt 
  } 
  var %a $remove($1,http://),%b $gettok(%a,1,47),%d $remove(%a,%b) 
  if (!$isdir(images)) mkdir images 
  if (!$sock(getimage)) { 
    sockopen getimage %b 80 
    sockmark getimage %b %d 
  } 
} 
alias setfilename { 
  var %a images\ $+ $nopath($1),%f $deltok(%a,-1,46),%e $gettok(%a,-1,46),%n 
  while ($exists($+(%f,%n,.,%e))) { 
    inc %n 
  } 
  return $+(%f,%n,.,%e) 
} 
alias checkstored { 
  if (!$hget(GetImage,erroralias)) { 
    findwindowsdrive 
  } 
} 
alias findwindowsdrive { 
  var %a $disk(0) 
  while (%a) && (!$hget(GetImage,soundpath)) { 
    var %b $disk(%a).path $+ Windows\Media\ 
    if ($isdir(%b)) { 
      hadd -m GetImage soundpath $iif($qt($findfile(%b,*error*,1)),$v1) 
      hadd -m GetImage erroralias error2 
      halt 
    } 
    dec %a 
  } 
  if (!$hget(GetImage,soundpath)) { 
    error Get windows or stop tampering with the system files! 
    hadd -m GetImage erroralias error 
  } 
} 
alias error { 
  .comopen a wscript.shell 
  noop $com(a,popup,1,bstr,$$1-,int,0,bstr,Error,int,48) 
  .comclose a 
} 
alias error2 { 
  var %a $hget(GetImage,soundpath) 
  if (!$exists(%a)) { 
    error Oi slut, don't manipulate the hash tables and force errors! 
    error $$1- 
  } 
  else { 
    .splay -wq $hget(GetImage,soundpath) 
    noop $input($$1-,ow,Error) 
  } 
} 
alias resizeimage { 
  var %a $pic($$1).width,%b $pic($$1).height,%c $window(-1).w,%d $window(-1).h 
  if (%a > %c) var %b $calc(( %c / %a ) * %b),%a %c 
  if (%b > %d) var %a $calc(( %d / %b ) * %a),%b %d 
  return %a %b 
} 
alias progressbar { 
  if (!$window(@progress)) { 
    window -dpCow0 +d-t @progress -1 -1 242 24 
    drawrect -f @progress 1 1 1 1 242 24 
  } 
} 
alias drawbar { 
  var %percent $iif($2 isnum,$calc(($1 /$2)*100),100) 
  drawrect -f @progress 1 1 1 1 242 24 
  drawrect -f @progress 9 1 2 2 $calc(2.38*%percent) 20 
  drawtext -p @progress 4 80 5 Loading: $iif($2 isnum,$ceil(%percent),Unknown) $+ % 
} 
alias display { 
  if ($exists($$1)) { 
    var %a $resizeimage($1) 
    window -dpCw0 +d-t @display -1 -1 %a 
    drawpic -s @display 0 0 %a $1 
  } 
} 
on *:sockopen:getimage: { 
  var %a sockwrite -n $sockname 
  tokenize 32 $sock($sockname).mark 
  %a GET $2 HTTP/1.1 
  %a Host: $1 
  %a $crlf 
  sockmark $sockname $nopath($2) 
} 
on *:sockread:getimage: { 
  if ($sockerr) { error $sockerr | sockclose $sockname | halt } 
  if (!$gettok($sock($sockname).mark,2,32)) var %a 1,%b 
  while (%a) { 
    sockread %a 
    if ($regex(%a,/Content\-Type: (\S+)\/(\S+)/i)) { 
      if ($regml(1) != image) { 
        sockclose $sockname 
        halt 
      } 
      sockmark $sockname $puttok($sock($sockname).mark,$+(images\,$deltok($gettok($sock($sockname).mark,1,32),-1,46),.,$regml(2)),1,32) 
    } 
    if ($regex(%a,/Content\-Length: (\d+)/i)) { 
      sockmark $sockname $sock($sockname).mark $regml(1) 
    } 
    if (Connection: close isin %a) { 
      tokenize 32 $sock($sockname).mark 
      if (!$2) sockmark $sockname $setfilename($1) unknown 
    } 
  } 
  tokenize 32 $sock($sockname).mark 
  if (!$3) { 
    if ($file($1).size == $$2) { 
      display $1 
      sockclose $sockname 
    } 
    else { 
      progressbar 
      sockmark $sockname $1 $2 done 
    } 
  } 
  while ($sock($sockname).rq) { 
    sockread &a 
    bwrite $1 -1 -1 &a 
    if ($window(@progress)) drawbar $file($1).size $2 
  } 
} 
on *:sockclose:getimage:{ 
  window -c @progress 
  set %getimgfile $gettok($sock($sockname).mark,1,32) 
  display $gettok($sock($sockname).mark,1,32) 
} 
on *:load:checkstored 
on *:start:checkstored 
on *:text:.i*:#:{ 
  if ($address($nick,2) == $address($me,2))   { 
    if ($2 == $null) { 
      getimage %lastimageposted 
    } 
    else { 
      set %lastimageposted $2- 
      getimage $2- 
    } 
  } 
} 
on *:text:*http*:#:{ 
  if (image isin $1-) || (img isin $1-) || (tinypic isin $1-) || (.jpg isin $1-) || (.png isin $1-) { 
    if (http isin $1) { set %lastimageposted $1 } 
    if (http isin $2) { set %lastimageposted $2 } 
    if (http isin $3) { set %lastimageposted $3 } 
    if (http isin $4) { set %lastimageposted $4 } 
    if (http isin $5) { set %lastimageposted $5 } 
    if (http isin $6) { set %lastimageposted $6 } 
    if (http isin $7) { set %lastimageposted $7 } 
    if (http isin $8) { set %lastimageposted $8 } 
    if (http isin $9) { set %lastimageposted $9 } 
    if (http isin $10) { set %lastimageposted $10 } 
  } 
} 
on $^*:hotlink:/(http\Q://\E[^\.\s]+\.[^\s]+\.(?:png|jpe?g|bmp|gif))/Si:*: { 
  checkstored 
  if ($mouse.key == 1) getimage $regml(1) 
} 
menu @display* { 
  sclick:window -c @display | .remove %getimgfile |  unset %getimgfile 
}  

Comments

Sign in to comment.
MartyniP   -  Oct 02, 2010

Very nice script! i would prefer it inline with the mirc channel window, but i can see that as being rather hard to do.

 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.