# version:1.7 loader:pf # $Id: away.dsm,v 1.57 2010/01/26 18:19:33 brian Exp $ # # away.dsm - Away module for DarkStar/EPIC5 # Copyright (c) 2002, 2003 Brian Weiss # See the 'COPYRIGHT' file for more information. # # This script uses serial number 421 for all /ON hooks. # queue cleanup.away { ^alias -readlog; ^alias -remlog; ^on #305 421 -"*"; ^on #306 421 -"*"; ^on #hook 421 -"CONFIG AWAY_LOG_LEVEL *"; ^on #input 421 -"*"; ^on #msg 421 -"*"; ^on #notice 421 -"*"; ^on #public 421 -'% % *\$servernick()*'; ^on #public_other 421 -'% % *\$servernick()*'; ^on #timer 421 -"*"; }; addconfig -b AUTO_AWAY 1; addconfig AUTO_AWAY_TIME 1200; addconfig -b AUTO_UNSET_AWAY 0; addconfig -b AWAY_LOG 1; addconfig -b AWAY_LOG_ALWAYS 0; addconfig AWAY_LOGFILE $DS.USER_DIR/away.log; addconfig AWAY_LOG_LEVEL MSGS NOTICES; addconfig -b PUBLIC_AWAY 0; addconfig PUBLIC_AWAY_CHANNELS; addconfig -b SEND_AWAY_NOTICE 1; # Timestamp for last user input. This is necessary for auto-away. @ AWAY.LAST_INPUT = time(); # If we're already away when the module is loaded, create a timestamp. # This won't be accurate, of course, but it's better than nothing. for serv in ($myservers(0)) { if (serv > -1 && isaway($serv)) { @ AWAY.TIME.$encode($serv) = time(); }; }; alias readlog (file default "$CONFIG.AWAY_LOGFILE", void) { @ AWAY.NEWMSGS = []; if (fexist($file) == 1) { less $file; } else { xecho -b Logfile $file does not exist; }; }; alias remlog (file default "$CONFIG.AWAY_LOGFILE", void) { @ AWAY.NEWMSGS = []; if (fexist($file)) { @ unlink($file); xecho -b Removed logfile $file; } else { xecho -b Logfile $file does not exist; }; }; # # You have set yourself away. # on #-306 421 "*" { @ :serv = servernum($0); @ AWAY.TIME.$encode($serv) = time(); @ delarray(away.sent_notice.$serv); if (CONFIG.PUBLIC_AWAY) { if (CONFIG.PUBLIC_AWAY_CHANNELS) { for chan in ($CONFIG.PUBLIC_AWAY_CHANNELS) { if (match($chan $mychannels($serv))) { xeval -s $serv { describe $chan is away: $serverctl(GET $serv AWAY) [Log/${CONFIG.AWAY_LOG ? [ON] : [OFF]}]; }; }; }; }{ for chan in ($mychannels($serv)) { xeval -s $serv { describe $chan is away: $serverctl(GET $serv AWAY) [Log/${CONFIG.AWAY_LOG ? [ON] : [OFF]}]; }; }; }; }; }; # # You have unset away. # on #-305 421 "*" { @ :serv = servernum($0); @ delarray(away.sent_notice.$serv); if (CONFIG.PUBLIC_AWAY && AWAY.TIME[$encode($serv)]) { @ :away_time = time() - AWAY.TIME.$encode($serv); if (CONFIG.PUBLIC_AWAY_CHANNELS) { for chan in ($CONFIG.PUBLIC_AWAY_CHANNELS) { if (match($chan $mychannels($serv))) { xeval -s $serv { describe $chan is back [Gone $tdiff($away_time)]; }; }; }; }{ for chan in ($mychannels($serv)) { xeval -s $serv { describe $chan is back [Gone $tdiff($away_time)]; }; }; }; }; if (AWAY.NEWMSGS) { xecho -b You have $AWAY.NEWMSGS new message${AWAY.NEWMSGS > 1 ? [s] : []}.; }; }; # # Restrict the value of the AWAY_LOG_LEVEL config variable. # on #-hook 421 "CONFIG AWAY_LOG_LEVEL *" { @ CONFIG.AWAY_LOG_LEVEL = toupper($CONFIG.AWAY_LOG_LEVEL); @ :levels = split(, $CONFIG.AWAY_LOG_LEVEL); for lvl in ($levels) { if (!match($lvl MSGS NOTICES PUBLICS)) { xecho -b Unknown level: $lvl; xecho -b Valid levels: MSGS NOTICES PUBLICS; @ :levels = remw($lvl $levels); }; }; if (levels != CONFIG.AWAY_LOG_LEVEL) { defer dset AWAY_LOG_LEVEL ${levels ? levels : [$2-]}; }; }; # # Update TS for last input and check for auto-unset-away. # on #-input 421 "*" { @ AWAY.LAST_INPUT = time(); if (CONFIG.AUTO_UNSET_AWAY) { for serv in ($myservers(0)) { if (isaway($serv)) { xeval -s $serv { //away; }; }; }; }; }; on #-msg 421 "*" { @ :serv = servernum(); if (CONFIG.SEND_AWAY_NOTICE && isaway($serv) && finditem(away.sent_notice.$serv $0) < 0) { @ setitem(away.sent_notice.$serv $numitems(away.sent_notice.$serv) $0); xeval -s $serv { notice $0 I am currently away \($serverctl(GET $serv AWAY)\) [Gone since: $strftime($AWAY.TIME[$encode($serv)] %c)] [Log/${CONFIG.AWAY_LOG ? [ON] : [OFF]}]; }; }; if (CONFIG.AWAY_LOG && (isaway($serv) || CONFIG.AWAY_LOG_ALWAYS) && match(MSGS $CONFIG.AWAY_LOG_LEVEL)) { if ((:fd = open($CONFIG.AWAY_LOGFILE W)) > -1) { @ write($fd [$strftime(%x %X)] MSG <$0!$userhost()> $1-); @ close($fd); }; @ AWAY.NEWMSGS++; }; }; on #-notice 421 "*" { @ :serv = servernum(); if (CONFIG.AWAY_LOG && (isaway($serv) || CONFIG.AWAY_LOG_ALWAYS) && match(NOTICES $CONFIG.AWAY_LOG_LEVEL)) { if ((:fd = open($CONFIG.AWAY_LOGFILE W)) > -1) { @ write($fd [$strftime(%x %X)] NOTICE <$0!$userhost()> $1-); @ close($fd); }; @ AWAY.NEWMSGS++; }; }; for hook in (public public_other) { ^on #-$hook 421 '% % *\$servernick()*' { @ :serv = servernum(); if (CONFIG.AWAY_LOG && (isaway($serv) || CONFIG.AWAY_LOG_ALWAYS) && match(PUBLICS $CONFIG.AWAY_LOG_LEVEL)) { if ((:fd = open($CONFIG.AWAY_LOGFILE W)) > -1) { @ write($fd [$strftime(%x %X)] PUBLIC $1 <$0!$userhost()> $2-); @ close($fd); }; @ AWAY.NEWMSGS++; }; }; }; # # Set ourselves away if auto-away is enabled and we # have been idle longer than $CONFIG.AUTO_AWAY_TIME. # on #-timer 421 "*" { if (CONFIG.AUTO_AWAY && CONFIG.AUTO_AWAY_TIME > 0) { @ :diff = time() - CONFIG.AUTO_AWAY_TIME; @ :minutes = CONFIG.AUTO_AWAY_TIME / 60; if (diff >= AWAY.LAST_INPUT) { for serv in ($myservers(0)) { if (!isaway($serv)) { xeval -s $serv { //away Auto-away after $minutes minute${minutes > 1 ? [s] : []}; }; }; }; }; }; };