All pastes #104457 Raw Edit

Unnamed

public text v1 · immutable
#104457 ·published 2006-07-28 22:10 UTC
rendered paste body
; away.mrc - mIRC Away Script
; By: Guillaume Lafrance (guillaume.lafrance@gmail.com)
; Version 2.7
; Last updated on Jul 27 2006 10:35 AM EDT (GMT -4)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;                                                                         ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;Version history;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;                                                                         ;
; (2.7) Will now work properly after using /away to set as back.          ;
; (2.6b) Made the dialog look better.                                     ;
; (2.6a) Fixed ugly bug.                                                  ;
; (2.6) Fixed major bug that made the script useless (OOPS!)              ;
; (2.5a) Fixed minor installer bug and added instrunctions on how to      ;
;        open the dialog                                                  ;
; (2.5) Added dialog and auto-away reason                                 ;
; (2.4) Will now work when someone notices you or performs an action that ;
;       has you in it.                                                    ;
; (2.3) /away now sets you as away on all servers                         ;
; (2.2) Improved 2.1 modification, added "toggle auto-notice" and         ;
;       dialog project started                                            ;
; (2.1) On load, if mIRC version is not 6.16, will tell user that I have  ;
;       not tested the script on that version of mIRC. It will also check ;
;       if all variables are present when starting mIRC. User can now set ;
;       the notice to what he wants.                                      ;
; (2.0) On load, if Away Script is already installed, script will echo    ;
;       instructions on updating to it, based on version installed.       ;
; (1.9) On unload, asks "Are you going to be updating?" if yes, idle      ;
;       setting is not unset. Also made install part to install but leave ;
;       idle setting intact when idle setting is present. This is to      ;
;       update.                                                           ;
; (1.8) Fixed qwery event notify                                          ;
; (1.7) This time, script will not set you away if you are already away   ;
; (1.6) Antiflood 5 sec per nick protection (By Segosa)                   ;
; (1.5) Will not set you automatically away if you are already away (or   ;
;       so I thought)                                                     ;
; (1.4) Uninstall button finished                                         ;
; (1.3) About button updated, uninstall button project started            ;
; (1.2) Unloading removes variables                                       ;
; (1.1) No more limit to # of notices that can be sent per user (Only one ;
;       user could see message)                                           ;
; (1.0) First version                                                     ;
;                                                                         ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; This script handles all AWAY details.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Events
;
; this installs the script when loaded
;
on 1:load:/install
; happens during mIRC startup and script installation
on 1:start:/initialize
;
; uninstall the script (happens when it is unloaded)
on 1:unload:/uninstall
;
; markes you as back when you say something
#away on
on 1:input:#:{
  ; just return if user isn't away
  if ( $away == $false ) goto dontback
  ; user is away... don't call /setback if user does something that no 
  ; one will see ...
  ; handle local command that is not an action
  if ( $left($1,1) == / && $left($1,3) != /me ) goto dontback
  ; call /setback
  setback
  :dontback
}
#away end

alias back {
  /allaway
  set %away.message $+([,$left($awaymsg,-14)) $+ ]
  set %away.since $+([,$left($right($awaymsg,6),-1))) $+ $asctime(tt) $+ ]
  set %away.for $+([,$duration($awaytime),])
  /me is back $chr(124) Back from: %away.message - Since: %away.since - For: %away.for
  unset %away*
}

alias back2 { 
  /allaway
  set %away.message $+([,$left($awaymsg,-14)) $+ ]
  set %away.since $+([,$left($right($awaymsg,6),-1))) $+ $asctime(tt) $+ ]
  set %away.for $+([,$duration($awaytime),])
  /echo 0,1Away-System $+ $chr(58) Back from: %away.message - Since: %away.since - For: %away.for
  unset %away*
}


#notice off
; notifies a user that says your name while you are away that you are 
; away
on *:text:*:*:{
  if (($away) && ($me isincs $1-)) {
    if (!$eval($+(%,away.floodprot.,$nick),2)) {
      ; he doesn't have a variable set like %away.floodprot.hisnick so we
      ; tell him we're away
      set %away.message $+([,$left($awaymsg,-14)) $+ ]
      set %away.since $+([,$left($right($awaymsg,6),-1))) $+ $asctime(tt) $+ ]
      set %away.for $+([,$duration($awaytime),])
      /me is back $chr(124) Back from: %away.message - Since: %away.since - For: %away.for
      ; and set the variable %away.floodprot.hisnick with /set to be 
      ; unset in 5 seconds
      set -u5 %away.floodprot. $+ $nick 1
    }
  }
}
on *:notice:*:*:{
  if ($away) {
    if (!$eval($+(%,away.floodprot.,$nick),2)) {
      ; he doesn't have a variable set like %away.floodprot.hisnick so we
      ; tell him we're away
      set %away.message $+([,$left($awaymsg,-14)) $+ ]
      set %away.since $+([,$left($right($awaymsg,6),-1))) $+ $asctime(tt) $+ ]
      set %away.for $+([,$duration($awaytime),])
      /me is back $chr(124) Back from: %away.message - Since: %away.since - For: %away.for
      ; and set the variable %away.floodprot.hisnick with /set to be 
      ; unset in 5 seconds
      set -u5 %away.floodprot. $+ $nick 1
    }
  }
}
on *:action:*:*:{
  if (($away) && ($me isincs $1-)) {
    if (!$eval($+(%,away.floodprot.,$nick),2)) {
      ; he doesn't have a variable set like %away.floodprot.hisnick so we
      ; tell him we're away
      set %away.message $+([,$left($awaymsg,-14)) $+ ]
      set %away.since $+([,$left($right($awaymsg,6),-1))) $+ $asctime(tt) $+ ]
      set %away.for $+([,$duration($awaytime),])
      /me is back $chr(124) Back from: %away.message - Since: %away.since - For: %away.for
      ; and set the variable %away.floodprot.hisnick with /set to be 
      ; unset in 5 seconds
      set -u5 %away.floodprot. $+ $nick 1
    }
  }
}


; notifies user that tries to query you while you are away that you are
; away
on *:TEXT:*:?: {
  if $away {
    if (!$eval($+(%,away.floodprot.,$nick),2)) {
      ; he doesn't have a variable set like %away.floodprot.hisnick so we
      ; tell him we're away
      set %away.message $+([,$left($awaymsg,-14)) $+ ]
      set %away.since $+([,$left($right($awaymsg,6),-1))) $+ $asctime(tt) $+ ]
      set %away.for $+([,$duration($awaytime),])
      /me is back $chr(124) Back from: %away.message - Since: %away.since - For: %away.for
      ; and set the variable %away.floodprot.hisnick with /set to be
      ; unset in 5 seconds
      set -u5 %away.floodprot. $+ $nick 1
    }
  }
}
#notice end

; Menu
;
menu menubar {
  ; away button
  &Away 
  ; brings you to the dialog
  .Dialog:/config
  ; lets you turn on or off auto-away system
  .Toggle auto-away ( [ $group(#away) ] ):{
    if ( $group(#away) == on ) {
      .disable #away
      .timeraway off
    }
    else {
      .enable #away
      .timeraway 1 %away.idle /idlecheck
    }
  }
  .Toggle auto-notice ( [ $group(#notice) ] ):{
    if ( $group(#notice) == on ) {
      .disable #notice
    }
    else {
      .enable #notice
    }
  }
  ; auto-away reason setting
  .Change Auto-Away Reason: {
    set %away.auto.reason $?="Enter auto-away reason"
    if ( %away.auto.reason != $null ) {
      .echo 12 -a Auto-away reason changed to " $+ %away.auto.reason $+ "
    }
    else {
      .set %away.auto.reason Automatically set away
      .echo 12 -a Auto-away reason field was empty! Default text " $+ %away.auto.reason $+ " was applied.
    }
  }

  ; lets you change idle time needed to be automatically marked away
  .Change Idle Time ( $+ [ $duration(%away.idle ) ] $+ ):{
    .timeraway off
    set %away.tmp $?="Enter idle time in minutes"
    if ( %away.tmp == $null ) {
      %away.idle = 30 * 60
      echo 12 -a You didn't enter anything, idle time set to 30 mins.
    }
    else {
      if ( %away.tmp != $null ) { %away.idle = %away.tmp }
      %away.idle = %away.idle  * 60
      echo 12 -a Idle time set to $duration(%away.idle).
      if ( %away.idle != 0 ) { .timeraway 1 %away.idle /idlecheck }
    }
  }
  ; lets you change the part before the ":" in the away notice 
  .Change away notice:{
    set %away.msg $?="Enter your new away notice (the part before the :)"
    if ( %away.msg != $null ) {
      echo 12 -a Away notice set to %away.msg $+ : away msg
    }
    if ( %away.msg == $null ) {
      set %away.msg I'm away
      echo 12 -a You didn't enter a message, notice set to %away.msg $+ : away msg
    }
  }
  .-
  ; lets you uninstall this script
  .Uninstall:unload -rs " $+ $script $+ "
  ; tells you the version of the script
  .About:echo -a Away Script ( $+ %away.ver $+ ) by: Guillaume Lafrance (guillaume.lafrance@gmail.com)
}
; Aliases
;
; idlecheck (to check if you need to be automatically marked away)
alias -l idlecheck {
  ; restarts timer if you aren't on a channel
  if ( $chan(0) == 0 ) { .timeraway 1 %away.idle /idlecheck }
  elseif ( $away == $true ) goto dontidle
  elseif ( $idle >= %away.idle ) {
    .away %away.auto.reason
  }
  else { .timeraway 1 $calc(%away.idle - $idle + 1) /idlecheck }
  :dontidle
}

; setaway (marks you away)
alias -l setaway {
  if ( $away == $true ) { echo -a You are already AWAY! | return }
}

; back (marks you as back... [sends you to /setback])
alias back /setback

; setback (marks you as back)
alias -l setback {
  if ( $away == $false ) return
  ; you are no longer away
  .timeraway off
  away
  if ( $group(#away) == on ) .timeraway 1 %away.idle /idlecheck
}

; pre-install
alias -l install {
  if ( $version < 6.1 ) {
    set %away.questiontemp $?!=" $+ $nopath($script) has not been tested for $crlf $+ any mIRC version lower than 6.1! $crlf $+ You are running mIRC v. $+ $version $+ . $crlf $+ Do you still want to install?"
    if ( %away.questiontemp == $true ) {
      .install2
      notice $me If this script works well with your version of mIRC ( $+ $version $+ ), please notify me at guillaume.lafrance@gmail.com
    }
    if ( %away.questiontemp == $false ) { 
      echo 4 -a Installation aborted
      unload -rs " $+ $script $+ "
      unset %away.questiontemp
      halt
    }
  }
  else { 
    .install2
  }
}

; installs this script
alias -l install2 {
  if ( %away.questiontemp == $false ) {
    unload 
  }
  set %away.vertemp 2.7
  if ( %away.ver == %away.vertemp ) {
    echo 7 -a Away Script ( $+ $nopath($script) $+ ) version %away.ver is already loaded!
    unset %away.vertemp
    unset %away.questiontemp
    halt
  }
  elseif (%away.ver > %away.vertemp) {
    echo 7 -a You are trying to install an older version of the script already installed!
    unset %away.vertemp
    unset %away.questiontemp
    halt
  }
  elseif ( %away.ver < 1.9 ) {
    echo 7 -a Away Script ( $+ $nopath($script) $+ ) version %away.ver is already loaded! To update to %away.vertemp $+ , unload %away.ver (Commands -> Away -> Uninstall) and try again.
    unset %away.vertemp
    unset %away.questiontemp
    halt
  }
  elseif ( %away.ver >= 1.9 ) {
    echo 7 -a Away Script ( $+ $nopath($script) $+ ) version %away.ver is already loaded! To update to %away.vertemp $+ , unload %away.ver (Commands -> Away -> Uninstall) click yes and try again.
    unset %away.vertemp
    unset %away.questiontemp
    halt
  }
  if ( %away.idle != $null ) {
    ; sets script version number and initializes
    set %away.ver %away.vertemp
    unset %away.vertemp
    unset %away.questiontemp
    if (( %away.msg == $null ) || ( %away.msg == $false )) {
      set %away.msg I'm away
      echo 12 -a Away Script ( $+ $nopath($script) $+ ) has been updated to version %away.ver $+ .
      halt
    }
    else {
      ; shows you that the script is updated
      echo 12 -a Away Script ( $+ $nopath($script) $+ ) has been updated to version %away.ver $+ .
      halt
    }
  }
  if ( %away.msg != $null ) {
    ; sets script version number and initializes
    set %away.ver %away.vertemp
    unset %away.vertemp
    unset %away.questiontemp
    if (( %away.idle == $null ) || ( %away.idle == $false )) {
      set %away.idle = 30 * 60
      echo 12 -a Away Script ( $+ $nopath($script) $+ ) has been updated to version %away.ver $+ .
    }
    else {
      ; shows you that the script is updated
      echo 12 -a Away Script ( $+ $nopath($script) $+ ) has been updated to version %away.ver $+ .
      halt
    }
  }
  ; sets script version number and initializes
  set %away.ver %away.vertemp
  unset %away.vertemp
  unset %away.questiontemp
  ; sets default auto away for 30 minutes
  %away.idle = 30 * 60
  ; sets default auto-away reason
  set %away.auto.reason Automatically set away
  ; sets default away notice message
  set %away.msg I'm away 
  ; shows you that the script is loaded
  echo 12 -a Away Script ( $+ $nopath($script) $+ ) version %away.ver has been installed.
  config
}

; initializes this script - executed each time you run mIRC.
alias -l initialize {
  if ( %away.questiontemp == $false ) {
    unload 
  }
  if ( %away.questiontemp != $false ) {
    ; enables auto away system ( you can comment [add ; before line] these two lines if 
    ; you want to manually start auto-away system
    .enable #away
    .timeraway 1 %away.idle /idlecheck
    ; enables auto notice system ( you can comment [add ; before line] this line if you
    ;  want to manually start auto-notice system
    .enable #notice
    ;tells you that this script is checking if necessary variables are present
    echo 12 -a Away Script is checking variables
    if (( %away.msg == $false ) || ( %away.msg == $null )) {
      echo 12 -a Away Script notice setting variable is missing!
      set %away.msg $?="The notice setting seems to be missing, $crlf $+ Enter your new away notice (the part before the :))"
      if ( %away.msg != $null ) {
        echo 12 -a Away notice set to %away.msg $+ : away msg
      }   
      if ( %away.msg == $null ) {
        set %away.msg I'm away
        echo 12 -a You didn't enter a message, notice set to %away.msg $+ : away msg
      }
    }

    if (( %away.auto.reason == $false ) || ( %away.auto.reason == $null )) {
      echo 12 -a Away Script auto-away reason variable is missing!
      set %away.auto.reason $?="The auto-away reason setting seems to be missing, $crlf $+ Enter your new reason"
      if ( %away.auto.reason != $null ) {
        .echo 12 -a Auto-away reason changed to " $+ %away.auto.reason $+ "
      }
      else {
        .set %away.auto.reason Automatically set away
        .echo 12 -a Auto-away reason field was empty! Default text " $+ %away.auto.reason $+ " was applied.
      }
    }
    if (( %away.idle == $false ) || ( %away.idle == $null )) {
      echo 12 -a Away Script idle time setting variable is missing!
      set %away.tmp $?="The idle time setting seems to be missing, $crlf $+ Enter idle time in minutes"
      if ( %away.tmp == $null ) {
        %away.idle = 30 * 60
        echo 12 -a You didn't enter anything, idle time set to 30 mins.
      }
      else {
        if ( %away.tmp != $null ) { %away.idle = %away.tmp }
        %away.idle = %away.idle  * 60
        echo 12 -a Idle time set to $duration(%away.idle).
        if ( %away.idle != 0 ) { .timeraway 1 %away.idle /idlecheck }
      }
    }
    ; tells you variables are ok
    echo 12 -a Away Script variables are all ok
    ; tells you that this script is running, as well as the version of the script
    echo 12 -a Away Script ( $+ $nopath($script) $+ ) version %away.ver by Guillaume Lafrance (guillaume.lafrance@gmail.com) is running.
    echo 12 -a To configure the Away Script, type /config
  }
}
; asks if you will be updating
alias -l uninstall {
  if ( %away.questiontemp == $false ) { 
    unset %away.questiontemp
    halt
  }
  else {
    set %away.question $?!="Are you going to be updating?" 
  }
  ; if you are going to update, 
  if (%away.question == $true) {
    echo 12 -a Away Script ( $+ $nopath($script) $+ ) version %away.ver is uninstalling.
    ; unsets all variables set by this script except script version
    unset %away.question
    ; tells you uninstall is done
    echo 12 -a Away Script ( $+ $nopath($script) $+ ) version %away.ver has been uninstalled for updating.
    ; tells you how to update
    echo 12 -a To update, load new script file (/load -rs [path to away.mrc])
    ; removes script version variable
    unset %away.ver
  }
  ; if you won't update,
  if (%away.question == $false) {
    ; tells you that script is uninstalling
    echo 12 -a Away Script ( $+ $nopath($script) $+ ) version %away.ver is uninstalling.
    ; unsets all variables set by this script except script version
    unset %away.idle
    unset %away.msg
    unset %away.auto.reason
    unset %away.question
    ; tells you uninstall is done
    echo 12 -a Away Script ( $+ $nopath($script) $+ ) version %away.ver has been uninstalled.
    ; removes script version variable
    unset %away.ver
  }
}
alias away {
  if ($0 != 0) {
    scid -at1 .raw away $1-
  }
  else {
    .timeraway off
    scid -at1 .raw away
    if ( $group(#away) == on ) .timeraway 1 %away.idle /idlecheck
  }
}
; DIALOG XD
alias config {
  dialog -m config config
}
dialog -l config {
  title "Away Script"
  size -1 -1 397 116
  option pixels
  button "Ok", 5, 317 64 65 25, ok
  button "Cancel", 6, 246 64 65 25, cancel
  box "Auto-away", 1, 12 8 377 52
  check "Auto-away on", 2, 18 22 100 32
  edit "", 3, 129 37 30 20
  text "Idle time (minutes)", 4, 127 18 100 17
  text "Auto-away reason", 7, 254 18 100 17
  edit "", 8, 234 36 140 20
  box "Auto-notice", 9, 12 60 226 52
  check "Auto-notice on", 10, 16 83 100 17
  text "Auto-notice prefix", 11, 127 69 100 17
  edit "", 12, 127 88 100 20
  link "Email me", 13, 269 94 56 17
  text "version", 14, 344 95 50 16
}

on *:dialog:config:init:*: {
  if ($group(#away) == on) { 
    did -c config 2
    set %autoawaystatus.tmp 1
  }
  else {
    set %autoawaystatus.tmp 0
  }
  if ($group(#notice) == on) {
    did -c config 10
    set %autoawaynotice.tmp 1
  }
  else {
    set %autoawaynotice 0
  }
  %tempawayidle = %away.idle / 60
  did -a config 8 %away.auto.reason
  did -a config 12 %away.msg
  did -a config 3 %tempawayidle
  did -a config 14 v $+ %away.ver
} 
on *:dialog:config:sclick:13:url -n guillaume.lafrance@gmail.com
on *:dialog:config:sclick:5: {
  if ($did(config,2).state != %autoawaystatus.tmp) {
    if ($did(config,2).state) {
      .enable #away 
      .echo 12 -a Auto-away is enabled
    }
    else {
      .disable #away 
      .echo 12 -a Auto-away is disabled 
    }
  } 
  if ($did(config,10).state != %autoawaynotice.tmp) {
    if ($did(config,10).state) {
      .enable #notice
      .echo 12 -a Auto-notice is enabled
    }
    else {
      .disable #notice
      .echo 12 -a Auto-notice is disabled
    }
  }
  if ($did(config,8) != %away.auto.reason) {
    if ($did(config,8) != $null) {
      .set %away.auto.reason $did(config,8)
      .echo 12 -a Auto-away reason changed to " $+ %away.auto.reason $+ "
    }
    else {
      .set %away.auto.reason Automatically set away
      .echo 12 -a Auto-away reason field was empty! Default text " $+ %away.auto.reason $+ " was applied.
    }
  }
  if ($did(config,12) != %away.msg)  {
    set %away.msg $did(config,12) {
      if ( %away.msg != $null ) {
        echo 12 -a Away notice prefix set to %away.msg $+ : away msg
      }
      if ( %away.msg == $null ) {
        set %away.msg I'm away
        echo 12 -a You didn't enter an away notice prefix, prefix set to %away.msg $+ : away msg
      }
    }
  }
  .timeraway off
  set %away.tmp $did(config,3)
  if ( %away.tmp == $null ) {
    %away.idle = 30 * 60
    echo 12 -a You didn't enter an idle time, idle time set to 30 mins.
  }
  else {
    if ( %away.tmp != $null ) { %away.idle.tmp = %away.tmp }
    %away.idle.tmp = %away.idle.tmp  * 60
    if (%away.idle != %away.idle.tmp) {
      set %away.idle %away.idle.tmp
      echo 12 -a Idle time set to $duration(%away.idle).
      if ( %away.idle != 0 ) { .timeraway 1 %away.idle /idlecheck }
    }
  }
  unset %away.idle.tmp
  unset %away.tmp
  unset %autoawaynotice.tmp
  unset %autoawaystatus.tmp
  unset %tempawayidle
}
on *:dialog:config:sclick:6: {
  unset %tempawayidle
  unset %autoawaynotice.tmp
  unset %autoawaystatus.tmp
}