;@@@
;@@@ DreamBot IRC Bot 5.4
;@@@ File description: ping mode
;@@@ Design & coding: DreamBot development team
;@@@ (C) Copyright 2004-2006 DreamBot development team. All rights reserved. 
;@@@

on 500:text:*pgmode*:#: {
  if ($1 == %c $+ pgmode) {
    if ($2 == $null) { .msg $nick Command incomplete. Syntax: %c $+ pgmode <ON|OFF>. | halt }
    if ($2 !== $null) {
      if ($2 == on) { .writeini -n ini\globals.ini Features PgMode On | .msg $nick The ping mode has been enabled. To see what your ping reply is type %c $+ ping. | halt }
      if ($2 == off) { .writeini -n ini\globals.ini Features PgMode Off | .msg $nick The ping mode has been disabled. | halt }
      else { .msg $nick $cl Error: Invalid parameter. Available parameters: ON/OFF | halt }
    }
  }
}
on 500:text:pgmode*:?: {
  if ($2 == $null) { .msg $nick Command incomplete. Syntax: /msg $me pgmode <ON|OFF>. | halt }
  if ($2 !== $null) {
    if ($2 == on) { .writeini -n ini\globals.ini Features PgMode On  | .msg $nick The ping mode has been enabled. To see what your ping reply is type %c $+ ping in a channel window. | halt }
    if ($2 == off) { .writeini -n ini\globals.ini Features PgMode Off | .msg $nick The ping mode has been disabled. | halt }
    else { .msg $nick $cl Error: Invalid parameter. Available parameters: ON/OFF | halt }
  }
}
on 1:text:*ping*:#: {
  if ($1 == %c $+ ping) { 
    if ($readini(ini\globals.ini, Features, PgMode) == on) { ctcp $nick ping }
    if ($readini(ini\globals.ini, Features, PgMode) == off) { halt }
  }
  else { halt }
}
on 1:CTCPREPLY:PING* {
  if ($2 == $null) { halt }
  else {
    %pt  = $ctime - $2
    if (%pt < 0) set %pt 0
    else { .notice $nick You had a ping reply of  $+ %pt $+  second(s). | unset %pt | halt }
  }
  halt
}
