Please explain what makes you think
hash tables have no limit, Tomao. Hashtables are, as everything, inherently limited by implementation. If your OS has no swap file, then it's limited by your available RAM. If your machine has no swap file and no available RAM, then I assume it will fail to add new items. The items within hashtables appear to be limited to 4096 bytes, much like variables.
I would suggest gooshie's first solution, alongside Tomao's suggestion, with the addition of a second file which stores the words, one to each line. Words would be added using /add_badword function, and removed by hand (I can't be bothered!). If speed becomes an issue (thooouuusands of items here), one could then quite easily then take the TRE regular expression module (which can compile regular expressions at runtime), write a cheap & dirty wrapper and compile. The resulting code would be fine for millions of items, assuming enough system resources are present
. I was tempted to write code for this, but this message is getting lengthy and it would be a good learning experience for others... and hey, I'm here if anyone who wants to give it a shot runs into any problems
alias conf_badword {
set %badwords_plaintext badwords.txt
set %badwords_table badwords.tab
}
alias add_badword {
var %item = $hget(badwords,0).item, %data = $mid($hget(badwords,%item).data,2,-2)
conf_badword
; leave more than enough space for the max 4096 per anything...
if ($len(%data) >= 2048) {
hadd -m badwords $calc(%item + 1) $+(/,$1,/iS)
}
else {
hadd -m badwords %item $+(/,%data,|,$1,/iS)
}
write %badwords_plaintext $1
hsave badwords %badwords_table
}
on 1:OPEN: conf_badword | hload %badwords_table
on ^*:OPEN:?:pmkban $1-
on *:TEXT:*:?:pmkban $1-
on *:ACTION:*:?:pmkban $1-
alias -l pmkban {
if ($hfind(badwords,$1-,0,R).data != $null) {
var %c,%i 1
while $comchan($nick,%i) {
%c = $v1
if $nick(%c,$me,~&@%) {
ban -ku600 %c $nick 2 Ten minute ban for language in private message!
}
inc %i
}
.ignore -u600 $nick 2
}
}