This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Write "correct" code

Old posts that have not been replied to for several years.
Locked
c
cerberus_gr
Halfop
Posts: 97
Joined: Fri Feb 07, 2003 8:57 am
Location: 127.0.0.1

Write "correct" code

Post by cerberus_gr »

Hello,

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
User avatar
CrazyCat
Revered One
Posts: 1359
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

well, imho, the second way should be better, but you may make a simpler one:
use your first version script, but when the script is loaded, you but all spamwords in an array.
When you add a spamword, make it added in both file and array.
So, you'll just have a few binds, and you read your file only when the eggdrop is loaded.

And a little tip: it's impossible to spam when joining :)
c
cerberus_gr
Halfop
Posts: 97
Joined: Fri Feb 07, 2003 8:57 am
Location: 127.0.0.1

Post by cerberus_gr »

You are right. This is the best that I have to do and in this way, I'll have 5-6 binds and also less needed cpu.

What exactly do you mean in your tip? ;)
User avatar
CrazyCat
Revered One
Posts: 1359
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

my tip is:
when someone joins a channel, he can't spam 'cuz he doesn't send any message.
So binding a join isn't usefull.
The only way to have a spam is pubm, msgm, act and notice.
the quit or part may contain spam, but it's too late.
You just have 4 binds :)
c
cerberus_gr
Halfop
Posts: 97
Joined: Fri Feb 07, 2003 8:57 am
Location: 127.0.0.1

Post by cerberus_gr »

As I said the same method checks for bad nicks etc. So, a join or a nick bind would be useful for me.
Also the sign and part binds are useful too, because in my channel there are some users who joins the chan, and immetiately quit, in order to spam in their quit msg, and they are doing this 5 or more times. So, when the bot detects spam msg in someone's quit message, it will ban his host ;)
User avatar
CrazyCat
Revered One
Posts: 1359
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

Yes, I was thinking you were doing something like this...
c
cerberus_gr
Halfop
Posts: 97
Joined: Fri Feb 07, 2003 8:57 am
Location: 127.0.0.1

Post by cerberus_gr »

:(
User avatar
CrazyCat
Revered One
Posts: 1359
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

smile, my opinion doesn't matter :)
c
cerberus_gr
Halfop
Posts: 97
Joined: Fri Feb 07, 2003 8:57 am
Location: 127.0.0.1

Post by cerberus_gr »

Wrong post for my (sad) emotion :P
Locked