Debug script

Release your script here.
State:
- Author
- What it does
- Perhaps a little guide.
- Also, if the snippet is of any use to the community, it has a chance of getting posted on the main page, so don't hesitate to submit/ask!

Debug script

Postby teppuli » Thu Apr 15, 2010 5:45 pm

This is quite old script made by me. It works only when you have mIRC user level 9 (/auser 9 nick)
Some features are maybe useless :D

Note: Log-feature can cause problems if script does'nt have permission for creating new file to mIRC folder
Code: Select all
;
; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
; X MSL debug v1.5 by teppuli                                                                       
; X DON'T TOUCH AUTHOR/COPYRIGHT/VERSION  WITHOUT AUTHOR'S           
; X PERMISSION                                                                                               
; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


; Some settings first:

alias -l ts_format {
  ; mIRC timestamp format (ex. timestamp: [13:13:13]  -> format: [*:*:*]) Use wildcards (* and ?):
  ; NOTE: For auto detection, TIMESTAMP_DETECT_AUTO
  return TIMESTAMP_DETECT_AUTO
}

alias -l use_logging {
  ; If enabled, script will log every usage (ON/OFF)
  return ON
}

alias -l logfile {
  ; Logfile name. Default is debuglog.txt
  return debuglog.txt
}


; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
; X Actual script (DONT TOUCH)            X
; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

; Get timestamp format
alias timestamp_format {
  if ($ts_format != TIMESTAMP_DETECT_AUTO) { return $ts_format }
  return $strip($replace($timestampfmt,n,?,h,?,s,?,m,?))
}

on 9:text:.msl *:#:{

  var %time = $ticks

 
  if (dns isin $2-) { var %waittime = 1000 }

  if ($2 == $chr(45) $+ wait) {
    if ($3 isnum) {
      if ($3 > 10000) { .notice $nick MSL - Too long wait time. Max 10000 milliseconds (10sec)  | halt }
      var %waittime = $3
      tokenize 32 $3-
    } 
    elseif ($3 !isnum) { .notice $nick MSL - Syntax error: -wait needs an argument: -wait <time>  | halt }
  }

  var %style = .notice $nick
  if ($gettok($1-,2,32) == -tochan) {

    tokenize 32 $2-

    var %style = .msg $chan
  }
 
  if ($active != status window) {
    window -a "status window"
  }


  if ($use_logging == ON) {
    if ($isfile($logfile)) {  .fopen debugfile $logfile | .fseek -l debugfile $calc($lines($logfile) + 1)  }
    if (!$isfile($logfile)) { .fopen -n debugfile $logfile }
  }

  if ($use_logging == ON) { .fwrite -n debugfile $crlf | .fwrite -n debugfile $time Trying to run: $iif($left($2-,1) == $chr(36),ret $+ urn $2-,$2-) - BY $nick  ( $+ $fulladdress $+ ) on channel $chan $+ . }
;create debug alias

  alias debugalias {  [ $iif($left($2-,1) == $chr(36),ret $+ urn $2-,$2-) ]  }

  var %numline = $line(status window,0)
  ; execute alias
  var %result = $debugalias
  ; sleep if required
  if (%waittime) { .sleep %waittime }
  ; calc
  var %expr = $ticks $+ - $+ %time
  [ [ %style ] ] MSL - Result: $replace($iif(%result,%result,No result),$chr(59) tochan,$null)  -  Took: $debugduration($calc(%expr)) seconds
  if ($use_logging == ON) { .fwrite -n debugfile $time Result: $replace($iif(%result,%result,No result),$chr(59) tochan,$null) - Took: $debugduration($calc(%expr)) seconds  }
  ; check for new lines in status window

  var %numnewline = $line(status window,0)

  if (%numnewline != %numline) {
    var %i =  1
    while (%i <= $calc(%numnewline - %numline)) {
      if ($strip($line(status window,$calc(%numline + %i))) != $chr($asc(-))) {
        var %t = $line(status window,$calc(%numline + %i))
        ; send
        [ [ %style ] ] MSL  - $iif($timestamp_format iswm $strip($gettok(%t,1,32)),$gettok($line(status window,$calc(%numline + %i)),2-,32),$line(status window,$calc(%numline + %i)))
        if ($use_logging == ON) { .fwrite -n debugfile $time Line:  $iif($timestamp_format iswm $strip($gettok(%t,1,32)),$gettok($line(status window,$calc(%numline + %i)),2-,32),$line(status window,$calc(%numline + %i)))  }

      }
      inc %i
    }
  }
  var %expr = $ticks $+ - $+ %time
  if ($use_logging == ON) { .fclose debugfile } 
  return

  :error
  var %errcod = $error
  [ [ %style ] ] MSL - Error: %errcod -  Took: $debugduration($calc(%expr)) seconds
  if ($use_logging == ON) {  .fwrite -n debugfile $time ID: %debugunid $+ :  Error: %errcod  -  Took: $debugduration($calc(%expr)) seconds }

  var %numnewline = $line(status window,0)
  if (%numnewline != %numline) {
    var %i =  1
    while (%i <= $calc(%numnewline - %numline)) {
      if ($strip($line(status window,$calc(%numline + %i))) != $chr($asc(-))) {
        var %t = $line(status window,$calc(%numline + %i))
        ; send line
        [ [ %style ] ] MSL  - $iif($timestamp_format iswm $gettok(%t,1,32),$gettok($line(status window,$calc(%numline + %i)),2-,32),$line(status window,$calc(%numline + %i)))
        if ($use_logging == ON) { .fwrite -n debugfile $time ID: %debugunid $+ : Line:  $iif($timestamp_format iswm $strip($gettok(%t,1,32)),$gettok($line(status window,$calc(%numline + %i)),2-,32),$line(status window,$calc(%numline + %i)))  }


      }
      inc %i
    }
  }
  var %expr = $ticks $+ - $+ %time
  if ($use_logging == ON) { .fclose debugfile } 
  reseterror

}
on 9:text:.msl:#:{ .notice $nick MSL debug v1.5 by teppuli - Usage: $1 <-wait <time> -tochan (optional)> <command>  | .notice $nick Arguments: -wait <time>: Wait <time> milliseconds after execution | .notice $nick -tochan: result to channel instead of notice   }
; debugduration for time elapsed
alias -l debugduration { return $iif($calc($1 / 1000) == 0,0.000,$calc($1 / 1000)) }
; sleep
alias -l sleep {
  ; sleep alias
  if ($isid) || ($0 != 1) || ($1 !isnum) || ($1 < 1) !return

  !var %f = $ticks $+ .wsf
  !write %f <job id="js"><script language="jscript">WScript.Sleep( $+ $1 $+ );</script></job>
  !.comopen %f WScript.Shell
  if (!$comerr) .comclose %f $com(%f,Run,3,bstr,%f,uint,0,bool,true)
  !.remove %f
}

; EOF

teppuli
 

Return to Mirc Scripting Release

Who is online

Users browsing this forum: No registered users and 0 guests

cron