Highlight Spam Blocker
Last updated: Version 1.0 -- 28-Apr-2010
This script will help you block the recent bout of spam IRC networks have been receiving, where spammers will flood a channel with user nicknames causing clients to highlight their name and draw attention to the spam. Use this script to bring peace again!
This script is highly commented for your convenience and safety.
Please examine every line of every script before you load it.
Instructions for installation:
Within mIRC, press ALT+R and click on the 'Remote' tab.
Goto 'File' > 'New' and paste in this script.
Goto 'File' > 'Save As...' and name the script: r_highlightspam.mrc
I can be found on EFnet in #raccoon
Enjoy.
~ Raccoon/EFnet.
; r_highlightspam.mrc 31-Mar-2010 by Raccoon/EFnet Version 1.0 28-Apr-2010
; This script has no dependencies. It goes in the Remotes tab in its own file.
;###############################################################################
;# Highlight Spam Blocker script for mIRC! by Raccoon on EFnet #
;# #
;# This script will ban or ignore users who spam the channel with several #
;# nicknames in a single line of text. It can be used to prevent complaints #
;# about being "woken up" by a client's highlighting features. #
;# #
;# The default settings will ban the user for 60 minutes if you have operator #
;# privlidges, or simply ignore the user for 5 minutes if you cannot ban them. #
;# You can modify this behavior in the section immediately below. Enjoy! #
;###############################################################################
; Actions to take against a user who Hightlight Spams.
ALIAS -l HighlightSpamTakeAction {
var %chan = $1
var %nick = $2
;# Ban user from channel! (if you have ops)
if $nick(%chan,$me,~!&@%) {
ban -ku3600 %chan %nick 2 Who disturbs our slumber?
}
;# Otherwise, ignore user instead.
else {
echo -tic info %chan * Ignoring %nick for 5 minutes for highlight spam.
.ignore -cntiu300 %nick 2
haltdef ; <- this hides the current line of text.
}
}
; Determine if user text is spammy.
ALIAS -l CatchHighlightSpam {
;# Maximum number of nicknames a user is allowed to say in their text.
var %MAXNICK = 5
;# Users with these prefixes are exempt. Eg, Channel Ops.
;# (~) Owner, (&) Admin, (*) Owner, (!) Admin, (@) Chan-Op, (%) Half-Op, (+) Voice
var %EXEMPT = ~&!*@%+
; ----- SCRIPT ----- Modify with care. -----
var %chan = $1
var %nick = $2
var %text = $strip($3-)
; abort if %nick has exempt status prefix.
if $nick(%chan,%nick,%exempt) { return }
; search for nicknames in user text string.
var %re = /([][A-Za-z0-9`^|\\{}_-]{4,})/g
noop $regex(%text,%re)
var %i = 1, %n = $regml(0), %cnt = 0
WHILE %i <= %n { ; loop through each word.
; is this word a nickname?
if ($regml(%i) ison %chan) inc %cnt
; have we found too many nicknames?
if (%cnt > %MAXNICK) {
HighlightSpamTakeAction %chan %nick
return $true
}
inc %i
}
return $false
}
; Channel text events.
On ^*:TEXT:*:#: { CatchHighlightSpam $chan $nick $1- }
On ^*:ACTION:*:#: { CatchHighlightSpam $chan $nick $1- }
On ^*:NOTICE:*:#: { CatchHighlightSpam $chan $nick $1- }
CTCP ^*:*:#: { CatchHighlightSpam $chan $nick $1- }
; Tell others about this script.
MENU Channel {
-
(Link) Highlight Spam Blocker: editbox -a Get this mIRC script to block highlight spammers. http://www.hawkee.com/snippet/7592/
}
; End of script.
; === Change Log ===
;
; v1.0 -- 28-Apr-2010
; * First public release of script for mIRC v6.35
;
; Check for updates and report bugs @ http://www.hawkee.com/snippet/7592/
Years ago, I remember some conclusion that ...
if %x > %y { return $true } ; <-- is faster
if (%x > %y) return $true ; <-- is slower
if (%x > %y) { return $true } ; <-- slower still
This is another reason why it's necessary to code for style over performance. What performs well one year, may not the next. Though, if I were performing a very resource heavy task like scanning a harddrive, sure, I'd squeeze every last bracket for an extra ounce of speed. But then again I'd probably write such a program in C++ or at least AutoHotkey.
Ah, you mean you removed the ( ) braces around if-conditions. Ok.
As far as speed goes, I used to be of your mind set -- back when I owned a Pentium 90 running Windows 95 with mIRC (didn't upgrade until 1999). But even if we went back in time on my old machine, the speed differences between the expanded version of my script and a condensed version would have been insignificant. Honestly, you would have to be in a channel receiving over 100 messages PER SECOND for there to be a noticeable speed difference.
When you begin to code for other people, and when you learn to reuse your old code for new purposes, you quickly discover that the benefits of highly commented and easy-to-read code means the difference between saving time and earning a paycheck... or pulling your hair out while your co-workers point fingers at you.
Programming today:
Besides. The mIRC parser condenses much of the code when the script is loaded into memory.
PS. Legibility is the only way to assure against malicious code. I strongly discourage anyone from running unreadable code -- Hawkee won't even permit unreadable code on this site!
WorldDMT:
- the braces makes the code slower
What braces are you referring to?
- for the /var u can use just one /var %var1 x,%var2 x,%varN ...
Yes, I can do that, but as convention I leave them as one-per-line when they are referencing $1, $2, $3... to improve readability. They are non-essential variables in the first place. Also, in support of your speed concern above, variables declare a smidge faster on separate lines than if put together on the same line (trivial, i don't care either way, just fyi).
- u can use only one alias
Yes, I know. I made it modular so the code could be easily read, modified, and adjusted without too much confusion. The majority of people using it have never scripted before, and can only read what is put in front of them. My method makes it harder to break the script if modified, and makes it easier to "talk someone through it".
I will post an "abbreviated version" when I get around to it.
PS. In your example, you want to include /break right after /haltdef, or replace it with /halt. Otherwise the loop will continue with %cnt > 5 and repeatedly kick/ignore a hundred more times.
hi
nice work Raccon but i have something about scripting
and that is the code like i suggest so just a suggestion and explanation of my comment
alias -l CatchHighlightSpam {
var %EXEMPT ~&!*@%+,%chan $1,%nick $2,%text $strip($3-)
if !$nick(%chan,%nick,%exempt) {
var %re /([][A-Za-z0-9`^|\\{}_-]{4,})/g
noop $regex(%text,%re)
var %n $regml(0),%cnt
while %n {
if ($regml(%n) ison %chan) inc %cnt
if %cnt > 5 {
if ($nick(%chan,$me,~!&@%)) ban -ku3600 %chan %nick 2 Who disturbs our slumber?
else {
echo -tic info %chan * Ignoring %nick for 5 minutes for highlight spam.
.ignore -cntiu300 %nick 2
haltdef
}
}
dec %n
}
}
}
on ^*:TEXT:*:#:CatchHighlightSpam # $nick $1-
on ^*:ACTION:*:#:CatchHighlightSpam # $nick $1-
on ^*:NOTICE:*:#:CatchHighlightSpam # $nick $1-
CTCP ^*:*:#:CatchHighlightSpam # $nick $1-
The newer constricted CODE boxes are my fault. I asked Hawkee to make them fixed-width, which made code text 1.5x as wide (avg). BUT I like Goochie's solution, so I wrote a script for it. You'll want to download AutoHotkey from www.autohotkey.com and run this...
; Hawkee Underscore, written in AutoHotkey.
:*:~hawk:: ; 28-Apr-2010 by Raccoon
VarSetCapacity(xstr,512,95)
xlen := 0
Loop, Parse, Clipboard, `n, `r
if (ylen := StrLen(A_LoopField)) > xlen
xlen := ylen
StringLeft, xstr, xstr, % xlen+2
clipsave := ClipboardAll
Clipboard := "
" Clipboard "r
n" xstr "
`r`n"
SendInput, ^v
Clipboard := clipsave
Return
_____________________________________________________________
Save that to foobar.ahk and double-click.
When you want to paste a CODE section, type ~hawk instead.
It was inspired by a hack Goochie discovered -- creating a solid line of underscores in order to expand the width of a CODE block beyond the constraints of the comments boundary.
Example:
_..----.._
]_.--._____[
___|'--'__..|--._
__ """ ; :
()_ """"---...__.'""!": / ___ :
"""---...__\]..__] | / [ 0 ] :
"""!--./ / """ :
__ ...._____;""'.__________..--..:_
/ !"''''''!''''''''''|''''/' ' ' ' \"--..__ __..
/ /.--. | | .' \' ' '.""--.{'.
_...__ >=7 //.-.: | |.' \ ._.__ ' '""'.
.-' / """"----..../ "">==7-.....:______ | \| | "";.;-"> \
""""; __.." .--"/"""""----...."""""----.....H_______\_!....'----""""]
_..---|._ __..--"" _!.-=_. """"""""""""""" ;"""
/ .-";-.'--...___ ." .-""; ';""-""-...^..__...-v.^___, ,__v.__..--^"--""-v.^v,
; ; |'. """-/ ./; ; ;\P. ; ; """"____; ;.--""""// '""<,
; ; | 1 ; ; '.: .' ;< ___.-'._.'------""""""____'..'.--""";;' o ';
'. \__:/__ ; ;--""()_ ;' /___ .-" ____---""""""" __.._ __._ '>., ,/;
\ \ /"""<--...__; '_.-'/; ""; ;.'.' "-..' "-. /"/ `__. '. "---";
'. 'v ; ; ;; \ \ .' \ ; //// _.-" "-._ ; : ; .-'__ '. ; .^".'
'. '; '. .'/ '. `-.__.' /;;; .o__.---.__o. ; : ; '"";;""' ;v^" .^
'-. '-.___.'<__v.^,v'. '-.-' ;|: ' : ` ;v^v^'.'. .;'.__/_..-'
'-...__.___...---""'-. '-'.;\ 'WW\ .'_____..>."^"-"""""""" fsc
'--..__ '"._..' '"-;;"""
"""---'""""""
____________________________________________________________________________________________________
Abbreviated version of this script, by popular demand.
; r_highlightspam_short.mrc 31-Mar-2010 by Raccoon/EFnet Version 1.a 28-Apr-2010
;###############################################################################
;# Highlight Spam Blocker script for mIRC! by Raccoon on EFnet #
;###############################################################################
On ^*:TEXT:*:#: { CatchHighlightSpam $1- }
On ^*:ACTION:*:#: { CatchHighlightSpam $1- }
On ^*:NOTICE:*:#: { CatchHighlightSpam $1- }
CTCP ^*:*:#: { CatchHighlightSpam $1- }
; Determine if user text is nick-spammy.
ALIAS -l CatchHighlightSpam {
;# Users with these prefixes are exempt. Eg, Channel Ops.
;# (~,*) Owner, (&,!) Admin, (@) Chan-Op, (%) Half-Op, (+) Voice
if $nick($chan,$nick,~&!*@%+) { return }
; search for nicknames in user text string.
var %re = /([][A-Za-z0-9`^|\\{}_-]{4,})/g
noop $regex($strip($1-),%re)
var %n = $regml(0), %cnt = 0
WHILE %n { ; loop through 'words'.
if ($regml(%n) ison $chan) inc %cnt
if (%cnt > 5) { ; Maximum number of nicknames in a sentence.
if $nick($chan,$me,~!&@%) { ; have ops? ban!
ban -ku3600 $chan $nick 2 Who disturbs our slumber?
} | else { ; don't have ops? ignore!
echo -tic info $chan * Ignoring $nick for 5 minutes for highlight spam.
.ignore -cntiu300 $nick 2 | haltdef
}
return ; done. spam thwarted.
}
dec %n
} }
; End of script.
__________________________________________________________________________________
=== Change Log ===
v1.0 -- 28-Apr-2010
I'm open to suggestions and feedback. Please comment below so I can make improvements. I am already aware that this script can be condensed to a much smaller size by removing all the code comments, stacking lines together, etc etc. It is intentionally written this way so very low-level users (newbies) can understand it and make changes more easily.
Comments will be tidied up every now and then. Take no offense.