1: You code is very bunched up.
You do an IF, open a brace and then goto a new line. However, when you close the brace, you place it at the end of a line, rathet than a on a new one.
While this isn't wrong, and is perfectly valid, it makes for hard to read code.
2: Indenting.
Along with doing braces, you should indent your code. It makes for far simpler reading again. You can tell what code, bellongs in which brace.
If you start doing a mass of if, while, foreach and for loops, you can find you get lost on howmany braces you have open. Indenting from the off, will allow you too know how many braces need closing, and making for simple backtracking.
Your code (first post) can be represented as follows.
Code: Select all
set badfile "badword.txt"
bind pubm - * pubm:badword
proc pubm:badword {nick uhost hand channel args } {
global badfile
if {![file exists $badfile]} {
putlog "Error: Le $badfile de dossier n'existent pas."
return
}
set file [open "$badfile" r]
set line [gets $file]
while {![eof $file]} {
foreach word [split $args] {
if {![string match "$word" [split $line]]} { continue }
set found 1
break
}
}
catch {close $file}
if {![info exists found]} { return 0 }
putlog "found"
}
See how you can tell where in the code you are. I do not state you have to take this approach, but it's far simpler to read.
Now back to the issues.
Scrap the code from the second post, it's more flawed than the first.
In the code above (in this post), you need to move the "gets" command. Unless it's in the loop, EOF will never be called.
What exactly are you trying to match in the foreach loop:
The whole line of IRC input?
Each word of IRC input?
If it's the whole line, then you don't even need the foreach loop, or $args.
It's it's each word, then you shouldn't be using $args (it is currently causing you to match against the whole line).
Otherwise, there isn't enything else wrong.