I have written a script which detects spam words on a chan and bans/kicks the user. The script works great, but I have a problem. So I would like some opinions about which is the best code:
(I save all spam words to a file and I add them with +spamword command and I want the script to detect spamwords from pub, nicks(join/change), quit and part messages)
Scenario 1 Too much scans
The 1st scenario is to have a bind for each option (join, part, nick, pub, etc) and every time to scan every line of the file and checks (string match) if any spamword of the file exists to the text.
example
Code: Select all
bind join - * spamword:join
bind part - * spamword:part
bind pub - * spamword:pub
bind sign - * spamword:sign
bind nick - * spamword:nick
proc spamword:join { nick uhost hand chan } {
spamword:check nick uhost chan nick
}
proc spamword:part { nick uhost hand chan {msg ""} } {
if {$msg != ""} { spamword:check nick uhost chan msg }
}
# (the same for other bind msgs)
proc spamword:check { nick uhost chan text } {
# reads every line of the file where spamwords save and uses the
# [string match * *] command to find the spammers
}
Scenario 2 Too much binds
The 2nd scenario is on start, to "create" a bind for each one of the words which exists in the file.
example
Code: Select all
set t [open file r]
while {![eof $t]} {
gets $t line
bind join - "$line" spamword:kickban
bind part - "$line" spamword:kickban
# The same for the other binds
}
proc spamword:kickban { param1 param2 ... } {
# bans and kicks the user
}
Which code would be quicker and which one uses less cpu and ram?
P.S. I know how I could do all these, and the above code is only for example. The only that I want is the idea and not the code
Thx