Do not Disturb - A QuakeNet pm blocker
From Scriptwiki
Revision as of 17:39, 23 April 2006 by Shenghi (talk | contribs) (fixed a bug logging to @allscripts in RAW 315)
Do not Disturb is a QuakeNet pm blocker based on Q account. 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 auth] ; 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 a Q auth to be specified ; ; remove removes a Q auth -- requires a Q auth to be specified ; - - - - - - - - - - - - - - - - - - - - - - - - - ; Version: ; v1.01 ; Fixed a bug logging to @AllScripts in RAW 315 ; - - - - - - - - - - - - - - - - - - - - - - - - - ;;;;;;;;;;;;;;;;;;;;;;;;; NOTE ;;;;;;;;;;;;;;;;;;;;;;;;; ; Do not Disturb logs some things to a window called ; ; @AllScripts. This window is hidden. If you want to ; ; view it by pressing F11, uncomment the following ; ; code. ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;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 } ;} ;;;;;;;;;;;;;;;;;;;;;;;;; EVENTS ;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;; ; on LOAD ; ;;;;;;;;;;; on *:load:{ linesep -s ;; writing the default ini if ($isfile(dnd.ini)) { echo -s Settings file (dnd.ini) already exists. Unloading script... unload -rs $script linesep -s return } ;; cc is short for control code 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 } ;;;;;;;;;;; ; 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 } ;;;;;;;;;;; ; 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 ] ] } 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- } ;;;;;;;;;;;;;;;;;;;;;;;;; MENU ITEMS ;;;;;;;;;;;;;;;;;;;;;;;;; menu channel,status { - DnD $iif(%dnd == on,off,on):dnd $iif(%dnd == on,off,on) }