Do not Disturb - A QuakeNet pm blocker

From Scriptwiki
Jump to: navigation, search

Do not Disturb is a QuakeNet pm blocker based on Q accounts. It will not work on other networks!

; - - - - - - - - - - - - - - - - - - - - - - - - - 
; Do Not Disturb 
; 
; Written by Shenghi
; Contact at #help.script @ irc.quakenet.org 
; 
; dnd.mrc 
; dnd.dnd 
; dnd.ini 
; - - - - - - - - - - - - - - - - - - - - - - - - - 
; A QuakeNet pm blocker based on Q auth 
; Usage: 
;  /dnd [on|off|allow|block|remove] [Q_account]
;    if no argument is passed a configuration dialog will pop up 
;    this is coming in a later version 
; 
;    on|off turns pm blocking on or off 
; 
;    allow|block allows or blocks a Q auth -- requires [Q_account] to be specified
; 
;    remove removes a Q auth -- requires [Q_account] to be specified
; - - - - - - - - - - - - - - - - - - - - - - - - - 
; Version 1.11
; - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 
;;;;;;;;;;;;;;;;;;;;;;;;; EVENTS ;;;;;;;;;;;;;;;;;;;;;;;;; 
 
;;;;;;;;;;; 
; on LOAD ; 
;;;;;;;;;;; 
on *:load:{ 
  linesep -s 
 
  ;; check whether or not there already is a file called dnd.ini
  if ($isfile(dnd.ini)) { 
    echo -s Options file (dnd.ini) already exists. Unloading script... 
    unload -rs $script 
    linesep -s 
    return 
  } 
  
  ;; check whether or not there already is a file called dnd.dnd
  if ($isfile(dnd.dnd)) { 
    echo -s User list (dnd.dnd) already exists. Unloading script... 
    unload -rs $script 
    linesep -s 
    return 
  } 

  ;; check whether or not there already is a hashtable called hDnd
  if ($hget(hDnd)) {
    echo -s User hash (hDnD) already exists. Unloading script... 
    unload -rs $script 
    linesep -s 
    return 
  } 

  if ($var(%dnd)) {
    echo -s Backing up %dnd in $eval(%__dbd__backup__,0)
    set %__dnd__backup__ %dnd
  }

  echo -s Turning on DnD
  set %dnd on

  echo -s Writing the options file
  writeini -n dnd.ini options cc block 
  writeini -n dnd.ini options showcc false 
  writeini -n dnd.ini options showblocked false 
  writeini -n dnd.ini options showaccepted true 
  writeini -n dnd.ini options showunknown true 
  writeini -n dnd.ini options blockunknown false 
  writeini -n dnd.ini options echoactive true 
  writeini -n dnd.ini options nickcolor 1 
 
  echo -s Loaded Do Not Disturb 
  linesep -s 
} 
 
 
;;;;;;;;;;;; 
; on START ; 
;;;;;;;;;;;; 
on *:start:{ 
  ;; free and create hDnd hashtable 
  if ($hget(hDnd)) hfree hDnd 
  hmake hDnd 
 
  ;; if dnd.dnd file exists, load allow/block hashtables 
  if ($isfile(dnd.dnd)) hload -b hDnd dnd.dnd 

  ;; check if %dnd exists, if it doesn't, set it on
  if (!$var(%dnd)) set %dnd on
} 
 
 
;;;;;;;;;;; 
; on OPEN ; 
;;;;;;;;;;; 
on ^*:OPEN:?:{ 
  ;; check if it happens on QNet 
  if (*.??.quakenet.org !iswm $server) || (%dnd == off) return 
 
  ;; notice the user that his query is pending 
  .notice $nick Query pending... 
 
  ;; halt the default opening of the window 
  haltdef 
 
  ;; check for control codes -- this should block most porn spam 
  if ($strip($1-) != $1-) && ($readini(dnd.ini,options,cc) == block) { 
    dnd_echo Blocked query from $nick ( $+ $fulladdress $+ ) containing control codes $+ $iif($readini(dnd.ini,options,showcc) == true,: $1-,.) 
    .notice $nick Query denied, message blocked. 
  } 
 
  ;; now it's time to check regular messages 
  ;; first, the easy part -- check if the user has usermode +x and if so 
  ;; use it to extract the Q auth 
  if ($right($site,19) == .users.quakenet.org) { 
 
    ;; $gettok($site,1,46) holds the users Q auth 
    ;; if the user is allowed to message, notice the query is accepted and let the query window open 
    if ($hget(hDnd,$gettok($site,1,46)) == allow) { 
      dnd_echo Accepted query from $nick ( $+ $fulladdress $+ ) $+ $iif($readini(dnd.ini,options,showaccepted) == true,: $1-,.) 
      if ($readini(dnd.ini,options,echoactive) == true) && (!$away) echo -ta �[ DND ]� Accepted query from $nick ( $+ $fulladdress $+ ) 
      query -n $nick 
      echo $nick $timestamp < $+ � $+ $readini(dnd.ini,options,nickcolor) $+ $nick $+ � $+ > $1- 
      window -g[1] $nick 
      .notice $nick Query accepted. 
    } 
    elseif ($hget(hDnd,$gettok($site,1,46)) == block) { 
      dnd_echo Blocked query from $nick ( $+ $fulladdress $+ )  $+ $iif($readini(dnd.ini,options,showblocked) == true,: $1-,.) 
      if ($readini(dnd.ini,options,echoactive) == true) && (!$away) echo -ta �[ DND ]� Blocked query from $nick ( $+ $fulladdress $+ ) 
      .notice $nick Query denied, message blocked. 
    } 
 
    ;; if a user is unknown we let faith (read: options) decide whether to accept or decline 
    else { 
      if ($readini(dnd.ini,options,blockunknown) == true) { 
        dnd_echo Denied query from $nick ( $+ $fulladdress $+ )  $+ $iif($readini(dnd.ini,options,showunknown) == true,: $1-,.) 
        if ($readini(dnd.ini,options,echoactive) == true) && (!$away) echo -ta �[ DND ]� Denied query from $nick ( $+ $fulladdress $+ ) 
        .notice $nick Query denied. 
      } 
      else { 
        dnd_echo Accepted query from $nick ( $+ $fulladdress $+ )  $+ $iif($readini(dnd.ini,options,showaccepted) == true,: $1-,.) 
        if ($readini(dnd.ini,options,echoactive) == true) && (!$away) echo -ta �[ DND ]� Accepted query from $nick ( $+ $fulladdress $+ ) 
        query -n $nick 
        echo $nick $timestamp < $+ � $+ $readini(dnd.ini,options,nickcolor) $+ $nick $+ � $+ > $1- 
        window -g[1] $nick 
        .notice $nick Query accepted. 
      } 
    } 
 
    ;; closing if ($right($site,19) == .users.quakenet.org) 
  } 
 
  ;; if the user wasn't using usermode +x we store the message and send a who to the server 
  ;; the query window remains closed so far, we can always open it later if the user is allowed to pm 
  else { 
    set %dndQueryAuth [ $+ [ $nick ] ] 1 
    set %dndQueryMessage [ $+ [ $nick ] ] $1- 
    set %dndQueryFulladdress [ $+ [ $nick ] ] $fulladdress 
    who $nick n%nat,990 
 
  } 
} 
 
;;;;;;;;;;; 
; RAW 354 ; 
;;;;;;;;;;; 
 
;; RAW 354 is the servers answer to the who request 
;; reference 990 is used to make sure it came from the on OPEN event 
;; if the user is authed with Q %dndQueryAuth [ $+ [ $nick ] ] is set to the auth, if he is not it remains 1 
raw 354:& 990 & *: {  
  set %dndQueryAuth [ $+ [ $3 ] ] $iif($4,$v1,1) 
  halt 
} 
 
;; reference 991 is used to make sure the raw reply comes from a menu request 
raw 354:& 991 & *:{ 
  set %dndAddAuth [ $+ [ $3 ] ] $iif($4,$v1,1) 
  halt 
} 
 
;;;;;;;;;;; 
; RAW 315 ; 
;;;;;;;;;;; 
 
;; unfortunately, raw 315 (End of /WHO list) does not have this reference 
raw 315:*:{ 
  ;;;;;;;;;;;;;;;;; 
  ; QUERY REQUEST ; 
  ;;;;;;;;;;;;;;;;; 
  if (%dndQueryAuth [ $+ [ $2 ] ]) { 
 
    ;; if the user was authed 
    if ($v1 != 1) { 
 
      ;; run the same check as in the on OPEN event 
      if ($hget(hDnd,%dndQueryAuth [ $+ [ $2 ] ]) == allow) { 
        dnd_echo Accepted query from $2 ( $+ %dndQueryFulladdress [ $+ [ $2 ] ] $+ ) $+ $iif($readini(dnd.ini,options,showaccepted) == true,: %dndQueryMessage [ $+ [ $2 ] ],.) 
        if ($readini(dnd.ini,options,echoactive) == true) && (!$away) echo -ta �[ DND ]� Accepted query from $2 ( $+ %dndQueryFulladdress [ $+ [ $2 ] ] $+ ) 
        query -n $2 
        echo $2 $timestamp < $+ � $+ $readini(dnd.ini,options,nickcolor) $+ $2 $+ � $+ > %dndQueryMessage [ $+ [ $2 ] ] 
        window -g[1] $2 
        .notice $2 Query accepted. 
      } 
      elseif ($hget(hDnd,%dndQueryAuth [ $+ [ $2 ] ]) == block) { 
        dnd_echo Blocked query from $2 ( $+ %dndQueryFulladdress [ $+ [ $2 ] ] $+ )  $+ $iif($readini(dnd.ini,options,showblocked) == true,: %dndQueryMessage [ $+ [ $2 ] ],.) 
        if ($readini(dnd.ini,options,echoactive) == true) && (!$away) echo -ta �[ DND ]� Blocked query from $2 ( $+ %dndQueryFulladdress [ $+ [ $2 ] ] $+ ) 
        .notice $2 Query denied, message blocked. 
      } 
 
      ;; if a user is unknown we let faith (read: options) decide whether to accept or decline 
      else { 
        if ($readini(dnd.ini,options,blockunknown) == true) { 
          dnd_echo Denied query from $2 ( $+ %dndQueryFulladdress [ $+ [ $2 ] ] $+ )  $+ $iif($readini(dnd.ini,options,showunknown) == true,: %dndQueryMessage [ $+ [ $2 ] ],.) 
          if ($readini(dnd.ini,options,echoactive) == true) && (!$away) echo -ta �[ DND ]� Denied query from $2 ( $+ %dndQueryFulladdress [ $+ [ $2 ] ] $+ ) 
          .notice $2 Query denied. 
        } 
        else { 
          dnd_echo Accepted query from $2 ( $+ %dndQueryFulladdress [ $+ [ $2 ] ] $+ )  $+ $iif($readini(dnd.ini,options,showaccepted) == true,: %dndQueryMessage [ $+ [ $2 ] ],.) 
          if ($readini(dnd.ini,options,echoactive) == true) && (!$away) echo -ta �[ DND ]� Accepted query from $2 ( $+ %dndQueryFulladdress [ $+ [ $2 ] ] $+ ) 
          query -n $2 
          echo $2 $timestamp < $+ � $+ $readini(dnd.ini,options,nickcolor) $+ $2 $+ � $+ > %dndQueryMessage [ $+ [ $2 ] ] 
          window -g[1] $2 
          .notice $2 Query accepted. 
        } 
      } 
    } 
 
    ;; if the user was not authed 
    else { 
      if ($readini(dnd.ini,options,blockunknown) == true) { 
        dnd_echo Denied query from $2 ( $+ %dndQueryFulladdress [ $+ [ $2 ] ] $+ )  $+ $iif($readini(dnd.ini,options,showunknown) == true,: %dndQueryMessage [ $+ [ $2 ] ],.) 
        if ($readini(dnd.ini,options,echoactive) == true) && (!$away) echo -ta �[ DND ]� Denied query from $2 ( $+ %dndQueryFulladdress [ $+ [ $2 ] ] $+ ) 
        .notice $2 Query denied. 
      } 
      else { 
        dnd_echo Accepted query from $2 ( $+ %dndQueryFulladdress [ $+ [ $2 ] ] $+ )  $+ $iif($readini(dnd.ini,options,showaccepted) == true,: %dndQueryMessage [ $+ [ $2 ] ],.) 
        if ($readini(dnd.ini,options,echoactive) == true) && (!$away) echo -ta �[ DND ]� Accepted query from $2 ( $+ %dndQueryFulladdress [ $+ [ $2 ] ] $+ ) 
        query -n $2 
        echo $2 $timestamp < $+ � $+ $readini(dnd.ini,options,nickcolor) $+ $2 $+ � $+ > %dndQueryMessage [ $+ [ $2 ] ] 
        window -g[1] $2 
        .notice $2 Query accepted. 
      } 
    } 
    unset %dndQueryAuth [ $+ [ $2 ] ] 
    unset %dndQueryMessage [ $+ [ $2 ] ] 
    unset %dndQueryFulladdress [ $+ [ $2 ] ] 
  } 
 
  ;;;;;;;;;;;; 
  ; ADD USER ; 
  ;;;;;;;;;;;; 
  elseif (%dndAddAuth [ $+ [ $2 ] ]) { 
    if ($v1 != 1) { 
      if (%dndAddAction [ $+ [ $2 ] ] == remove) { 
        hdel hDnd %dndAddAuth [ $+ [ $2 ] ] 
        echo - $+ $iif($readini(dnd.ini,options,echoactive) == true,ta,s) �[ DND ]�  Removed Q auth %dndAddAuth [ $+ [ $2 ] ] 
        hsave -b hDnd dnd.dnd 
      } 
      else { 
        hadd hDnd %dndAddAuth [ $+ [ $2 ] ] %dndAddAction [ $+ [ $2 ] ] 
        hsave -b hDnd dnd.dnd 
        echo - $+ $iif($readini(dnd.ini,options,echoactive) == true,ta,s) �[ DND ]�  $iif(%dndAddAction [ $+ [ $2 ] ] == allow,Allowing,Blocking) queries from Q auth %dndAddAuth [ $+ [ $2 ] ] 
      } 
    } 
    else echo - $+ $iif($readini(dnd.ini,options,echoactive) == true,ta,s) �[ DND ]�  User not authed with Q. 
    unset %dndAddAuth [ $+ [ $2 ] ] 
    unset %dndAddAction [ $+ [ $2 ] ] 
  } 
  halt 
} 
 
 
;;;;;;;;;;;;;;;;;;;;;;;;; PUBLIC ALIASES ;;;;;;;;;;;;;;;;;;;;;;;;; 
 
;;;;;;; 
; DND ; 
;;;;;;; 
alias dnd { 
  ;; syntax check 
  ;; turn dnd on/off 
  if ($regex($1-,/^(on|off)$/)) { 
    set %dnd $regml(1) 
    echo - $+ $iif($readini(dnd.ini,options,echoactive) == true,ta,s) �[ DND ]� Do Not Disturb turned $iif($regml(1) == on,on,off) 
  } 
  ;; allow/block a user 
  elseif ($regex($1-,/^(allow|block)\s(\w+)$/)) { 
    hadd hDnd $regml(2) $regml(1) 
    hsave -b hDnd dnd.dnd 
    echo - $+ $iif($readini(dnd.ini,options,echoactive) == true,ta,s) �[ DND ]�  $iif($regml(1) == allow,Allowing,Blocking) queries from Q auth $regml(2) 
  } 
  ;; remove a user 
  elseif ($regex($1-,/^remove\s(\w+)$/)) { 
    hdel hDnd $regml(1) 
    hsave -b hDnd dnd.dnd 
    echo - $+ $iif($readini(dnd.ini,options,echoactive) == true,ta,s) �[ DND ]� Removed Q auth $regml(1) 
  } 
  ;; dialog 
  elseif (!$0) { } 
  ;; else the syntax is wrong -- output an error 
  else echo -s * /dnd - Error: erronious syntax. 
 
} 
 
 
;;;;;;;;;;;;;;;;;;;;;;;;; PRIVATE ALIASES ;;;;;;;;;;;;;;;;;;;;;;;;; 
 
;;;;;;;;;;;; 
; dnd_echo ; 
;;;;;;;;;;;; 
alias -l dnd_echo { 
  if (!$window(@AllScripts)) { window -hk0nx @AllScripts } 
  echo @Allscripts � $+ $color(normal text) $+ $timestamp � $+ $color(info2 text) $+ $chr(91) DND $chr(93) � $+ $color(normal text) $+ $1- 
} 
 
 
;;;;;;;;;;;;;;;;;;;;; 
; dndMenuQueryAllow ; 
;;;;;;;;;;;;;;;;;;;;; 
alias -l dndMenuQueryAllow { 
  ;; check for mode +x 
  if ($right($ial($1).host,19) == .users.quakenet.org) { 
    ;; get Q auth from address and add it to hDnd 
    hadd hDnd $gettok($ial($1).host,1,46) allow 
    hsave -b hDnd dnd.dnd 
    echo - $+ $iif($readini(dnd.ini,options,echoactive) == true,ta,s) �[ DND ]�  Allowing queries from Q auth $gettok($ial($1).host,1,46) 
  } 
  ;; if the user did not have mode +x do a /WHO 
  else { 
    set %dndAddAuth [ $+ [ $1 ] ] 1 
    set %dndAddAction [ $+ [ $1 ] ] allow 
    who $1 n%nat,991 
  } 
} 
 
;;;;;;;;;;;;;;;;;;;;; 
; dndMenuQueryBlock ; 
;;;;;;;;;;;;;;;;;;;;; 
alias -l dndMenuQueryBlock { 
  ;; check for mode +x 
  if ($right($ial($1).host,19) == .users.quakenet.org) { 
    ;; get Q auth from address and add it to hDnd 
    hadd hDnd $gettok($ial($1).host,1,46) block 
    hsave -b hDnd dnd.dnd 
    echo - $+ $iif($readini(dnd.ini,options,echoactive) == true,ta,s) �[ DND ]�  Blocking queries from Q auth $gettok($ial($1).host,1,46) 
  } 
  ;; if the user did not have mode +x do a /WHO 
  else { 
    set %dndAddAuth [ $+ [ $1 ] ] 1 
    set %dndAddAction [ $+ [ $1 ] ] block 
    who $1 n%nat,991 
  } 
} 
 
;;;;;;;;;;;;;;;;;;;;;; 
; dndMenuQueryRemove ; 
;;;;;;;;;;;;;;;;;;;;;; 
alias -l dndMenuQueryRemove { 
  ;; check for mode +x 
  if ($right($ial($1).host,19) == .users.quakenet.org) { 
    ;; get Q auth from address and delete it from hDnd 
    hdel hDnd $gettok($ial($1).host,1,46) 
    hsave -b hDnd dnd.dnd 
    echo - $+ $iif($readini(dnd.ini,options,echoactive) == true,ta,s) �[ DND ]�  Removed Q auth $gettok($ial($1).host,1,46) 
  } 
  ;; if the user did not have mode +x do a /WHO 
  else { 
    set %dndAddAuth [ $+ [ $1 ] ] 1 
    set %dndAddAction [ $+ [ $1 ] ] remove 
    who $1 n%nat,991 
  } 
} 
 
;;;;; To prevent possible flooding, only 5 nicks will be allowed/blocked/removed at a time ;;;;; 
;;;;;;;;;;;;;;;;;;;;;;;; 
; dndMenuNicklistAllow ; 
;;;;;;;;;;;;;;;;;;;;;;;; 
alias -l dndMenuNicklistAllow { 
  var %i = 1 
  while ($gettok($1-,%i,32)) { 
    var %nick = $v1 
    ;; check for mode +x 
    if ($right($ial(%nick).host,19) == .users.quakenet.org) { 
      ;; get Q auth from address and add it to hDnd 
      hadd hDnd $gettok($ial(%nick).host,1,46) allow 
      hsave -b hDnd dnd.dnd 
      echo - $+ $iif($readini(dnd.ini,options,echoactive) == true,ta,s) �[ DND ]�  Allowing queries from Q auth $gettok($ial(%nick).host,1,46) 
    } 
    ;; if the user did not have mode +x do a /WHO 
    else { 
      set %dndAddAuth [ $+ [ %nick ] ] 1 
      set %dndAddAction [ $+ [ %nick ] ] allow 
      who %nick n%nat,991 
    } 
    inc %i 
  } 
} 
 
;;;;;;;;;;;;;;;;;;;;;;;; 
; dndMenuNicklistBlock ; 
;;;;;;;;;;;;;;;;;;;;;;;; 
alias -l dndMenuNicklistBlock { 
  var %i = 1 
  while ($gettok($1-,%i,32)) { 
    var %nick = $v1 
    ;; check for mode +x 
    if ($right($ial(%nick).host,19) == .users.quakenet.org) { 
      ;; get Q auth from address and add it to hDnd 
      hadd hDnd $gettok($ial(%nick).host,1,46) block 
      hsave -b hDnd dnd.dnd 
      echo - $+ $iif($readini(dnd.ini,options,echoactive) == true,ta,s) �[ DND ]�  Blocking queries from Q auth $gettok($ial(%nick).host,1,46) 
    } 
    ;; if the user did not have mode +x do a /WHO 
    else { 
      set %dndAddAuth [ $+ [ %nick ] ] 1 
      set %dndAddAction [ $+ [ %nick ] ] block 
      who %nick n%nat,991 
    } 
    inc %i 
  } 
} 
 
;;;;;;;;;;;;;;;;;;;;;;;;; 
; dndMenuNicklistRemove ; 
;;;;;;;;;;;;;;;;;;;;;;;;; 
alias -l dndMenuNicklistRemove { 
  var %i = 1 
  while ($gettok($1-,%i,32)) { 
    var %nick = $v1 
    ;; check for mode +x 
    if ($right($ial(%nick).host,19) == .users.quakenet.org) { 
      ;; get Q auth from address and add it to hDnd 
      hdel hDnd $gettok($ial(%nick).host,1,46) 
      hsave -b hDnd dnd.dnd 
      echo - $+ $iif($readini(dnd.ini,options,echoactive) == true,ta,s) �[ DND ]�  Removed Q auth $gettok($ial(%nick).host,1,46) 
    } 
    ;; if the user did not have mode +x do a /WHO 
    else { 
      set %dndAddAuth [ $+ [ %nick ] ] 1 
      set %dndAddAction [ $+ [ %nick ] ] Remove 
      who %nick n%nat,991 
    } 
    inc %i 
  } 
} 
 
 
;;;;;;;;;;;;;;;;;;;;;;;;; MENU ITEMS ;;;;;;;;;;;;;;;;;;;;;;;;; 
menu channel,status { 
  - 
  DnD $iif(%dnd == on,off,on):dnd $iif(%dnd == on,off,on) 
} 
 
menu query { 
  - 
  DnD 
  .Allow:dndMenuQueryAllow $1 
  .Block:dndMenuQueryBlock $1 
  .Remove:dndMenuQueryRemove $1 
} 
 
menu nicklist { 
  - 
  DnD 
  .Allow:dndMenuNicklistAllow $snick(#,1) $snick(#,2) $snick(#,3) $snick(#,4) $snick(#,5) 
  .Block:dndMenuNicklistBlock $snick(#,1) $snick(#,2) $snick(#,3) $snick(#,4) $snick(#,5) 
  .Remove:dndMenuNicklistRemove $snick(#,1) $snick(#,2) $snick(#,3) $snick(#,4) $snick(#,5) 
}

This pm blocker will log some things to a hidden window called @AllScripts. To be able to view/hide the window by pressing the F11 key add the following lines at the end of the script:

alias F11 {
  if ($window(@AllScripts).state == maximized) { window -n @AllScripts }
  elseif ($window(@AllScripts).state == hidden) { window -x @AllScripts }
  elseif ($window(@AllScripts).state == normal) { window -x @AllScripts }
}