Antidle — File Browser

Antidlev1.03 / Antidlev1.03 / Antidle.mrc

Antidle.mrc — 7.9 KB — Download this file

;_____________________________________________
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯                                                                                                                                                                     
; Antidle
;
; This antidle time is an adaptation from antidle feature
; from FeedbacK (mIRC script) coded by me
;
; http://www.feedbackscript.cjb.net
;                                                                         
; Mal-Functi  /  jpedrobc@clix.pt  /  irc.ptnet.org (PTnet)                    
;_____________________________________________
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
;
;_____________[ Get a network name ] ________________________________________

alias -l _antidle.listNetworks {
  var %win = @_temp._antidle.listNetworks, %x = 1, %i, %total = $server(0)
  if ($window(%win)) { return %win }
  elseif (!%total) { return }
  window -hsl %win
  while ($server(%x).group) {
    %i = $ifmatch
    if (%i !isnum) && (!$fline(%win,%i,1)) { aline %win %i }
    inc %x
  }
  return %win
}
alias -l _antidle.getNetwork {
  var %dname = antidle.getNetwork, %net
  if ($dialog(%dname)) { return }
  %net = $dialog(%dname,%dname,-3)
  if (%net != $null) { return $ifmatch }
}
dialog -l antidle.getNetwork {
  title "Antidle - Add network"
  size -1 -1 125 50
  option dbu
  box "", 1, 3 2 119 28
  button "&Select", 2, 45 34 37 12, default ok
  button "&Cancel", 3, 85 34 37 12, cancel
  combo 4, 8 11 110 100, result size edit drop
}
on *:DIALOG:antidle.getNetwork:*:*:{
  if ($devent == init) {
    if ($_antidle.listNetworks) { filter -wo $ifmatch $dname 4 }
    if ($didwm(4,$_network.active)) { did -c $dname 4 $ifmatch }
    else { did -c $dname 4 1 }
  }
  elseif ($devent == edit) && ($did == 4) { did $iif($did(4) != $null,-e,-b) $dname 2 }
}


;_____________[ Setup dialog ] ________________________________________

dialog -l antidle {
  title "Antidle - Options"
  size -1 -1 170 87
  option dbu

  text "&Network:", 1, 9 7 24 8
  combo 2, 34 6 59 50, size drop
  button "&Add", 3, 95 6 32 11
  button "&Remove", 4, 129 6 32 11

  box "", 5, 6 18 159 50
  check "&Enable antidle", 6, 12 27 50 10
  check "&Prevent antidle to work while you're away", 7, 12 39 123 10
  text "&Maximum seconds of idle time:", 8, 13 52 74 8
  edit "", 9, 95 50 64 11, right

  button "&Ok", 100, 88 72 37 11, ok
  button "&Cancel", 99, 128 72 37 11, cancel

  edit "", 1000, 0 0 0 0, hide
}
on *:DIALOG:antidle:*:*:{
  if ($devent == init) { 
    didtok $dname 2 32 $_antidle.allNetworks
    did -c $dname 2 1
    _antidle.loadOptions
  }
  elseif ($devent == sclick) {
    if ($did == 2) { _antidle.loadOptions }
    elseif ($did == 3) {
      var %net = $$_antidle.getNetwork
      if ($didwm(2,%net)) { did -c $dname 2 $ifmatch }
      else { did -ca $dname 2 %net }
      _antidle.loadOptions
    }
    elseif ($did == 4) && ($did(2).seltext != $null) {
      var %text = $ifmatch
      if (%text != $chr(40) $+ Unknown $+ $chr(41)) && ($input(Do you really want to remove $+(',%text,') settings?,128,Antidle)) {
        _antidle.addToHash %text
        did -d $dname 2 $did(2).sel
        did -c $dname 2 1
        did -r $dname 1000
        _antidle.loadOptions
      }
    }
    elseif ($istok(99 100,$did,32)) { 
      _antidle.saveOptions 
      _antidle.work
    }
  }
}
alias -l _antidle.allNetworks {
  var %x = 1, %i, %nets = (Unknown), %chr = $iif($1 isnum,$1,32)
  while ($ini($_antidle.iniFile,%x)) {
    %nets = $addtok(%nets,$ifmatch,%chr)
    inc %x
  }
  return %nets
}
alias -l _antidle.iniFile { return $+(",$scriptdirAntidleOptions.ini,") }
alias -l _antidle.loadOptions {
  var %dname = antidle, %net = $did(%dname,2).seltext
  _antidle.saveOptions
  if (%net == $null) { return }
  did -u %dname 6,7
  if ($_antidle.option(%net,antidle)) { did -c %dname 6 }
  if ($_antidle.option(%net,antidle.while.away)) { did -c %dname 7 }
  did -ra %dname 9 $_antidle.maxTime(%net)
  did -ra %dname 1000 %net
}
alias -l _antidle.saveOptions {
  var %dname = antidle, %net = $did(%dname,1000), %a = _antidle.addToHash %net
  if (%net == $null) { return }
  %a antidle $did(%dname,6).state
  %a antidle.while.away $did(%dname,7).state
  %a antidle.max.idle $did(%dname,9)
}
alias -l _antidle.addToHash {
  var %f = $_antidle.iniFile
  if ($2 == $null) || ($3 == $null) { remini %f $1-2 }
  else { writeini %f $1- }
}
alias -l _antidle.option {
  if ($2) { var %net = $1, %option = $2 }
  else { var %net = $_antidle.activeNetwork, %option = $1 }
  if (%option == $null) { return }
  if (%net == $null) { %net = (Unknown) }
  return $readini($_antidle.iniFile,%net,%option)
}


;_____________[ The reason for all this work ] ________________________________________

alias -l _antidle.activeNetwork {
  if ($network) { return $ifmatch }
  if ($server($server).group) && ($ifmatch !isnum) { return $ifmatch }
  return Unknown
}
alias -l _antidle.identString {
  var %ident = $$1, %chr = $iif($2 isnum,$2,32), %x = 1, %str, %y = $scon(0)
  while (%x <= %y) {
    %str = $addtok(%str,$scon(%x). [ $+ [ %ident ] ],%chr)
    inc %x
  }
  return %str
}
alias -l _antidle.work {
  var %cids = $_antidle.identString(cid), %x = 1
  while ($gettok(%cids,%x,32)) {
    scid -t1 $ifmatch _antidle.timerHandler $ifmatch
    inc %x
  }
}
alias -l _antidle.maxTime { 
  var %r
  if ($1) { %r = $_antidle.option($1,antidle.max.idle) }
  else { %r = $_antidle.option(antidle.max.idle) }
  return $iif(%r isnum 1-,$ifmatch,20) 
}
alias -l _antidle.awayAffect {
  if ($away) && (!$_options(antidle.while.away)) { return 1 }
  return 0
}
alias -l _antidle.timerHandler {
  var %cid = $1, %timer = $+(ANTIDLE,~,%cid), %net = $scid(%cid).network
  if ($timer(%timer)) {
    if ($timer(%timer).delay != $_antidle.maxTime) { scid -t1 %cid .timer $+ %timer -o 0 $_antidle.maxTime _antidle.timerHandler %cid  }
    if (!$_antidle.option(antidle)) {
      .timer $+ %timer off
      return
    }
    if ($_antidle.awayAffect) { return }
    scid -t1 %cid resetidle
    scid -t1 %cid !.msg $scid(%cid).me ^_antidle_^
  }
  elseif ($_antidle.option(antidle)) { scid -t1 %cid .timer $+ %timer -o 0 $_antidle.maxTime _antidle.timerHandler %cid }
}
on me:^&*:OPEN:?:^_antidle_^:{ halt }
on ^*:TEXT:^_antidle_^:?:{
  if ($nick == $me) { halt }
}
on *:DISCONNECT:{ 
  if ($timer($+(ANTIDLE,~,$cid))) { .timer $+ $ifmatch off }
}
on *:CONNECT:{ _antidle.work }



;_____________[ Addon musts ] ________________________________________

alias antidle {
  if ($1 == -u) { 
    if ($input(Do you really want to unload Antidle v $+ $_antidle.version $+ ?,128,Antidle)) {
      .timerANTIDLE~* off 
      .timer -mi 1 1 unload -rs $+(",$script,")
    }
  }
  elseif ($1 == -o) || ($1 == $null) { 
    if ($dialog(antidle)) { dialog -ve antidle }
    else { dialog -mn antidle antidle }
  }
  elseif ($1 == -a) { echo $color(info text) -ati2e * Antidle v $+ $_antidle.version $+  coded by Mal-Functi - JoaoPe@gmail.com (http://www.feedbackscript.has.it/) }
  elseif ($1 == -r) { 
    var %f = $_antidle.readmeFile
    if ($isfile(%f)) { .run %f }
    else { echo $color(ctcp text) -ti2ae * /antidle: no readme file available ( $+ $mid(%f,2,-1) $+ ) }
  }
  else { echo $color(ctcp text) -ti2ea * /antidle: sintax error ( /antidle [-u|-o|-a|-r] ) }
}
alias -l _antidle.readmeFile { return $+(",$scriptdirAntidleReadme.txt,") }
alias -l _antidle.version { return 1.03 }

on *:LOAD:{
  if ($version < 6) {
    echo $color(ctcp text) -ti2ae * Antidle v $+ $_antidle.version $+  needs mIRC v6.0 or higher to run properly
    unload -rs $+(",$script,")
  }
  else { echo $color(info text) -ti2ae * Antidle v $+ $_antidle.version $+  loaded. Check menubar. }
}
menu menubar {
  &Antidle
  .&Setup:{ antidle -o }
  .-
  .&Readme:{ antidle -r }
  .&About:{ antidle -a }
  .-
  .&Unload:{ antidle -u }
}