bind pub - !check check
proc check {nick uhost hand chan text} {
set t [open scripts/filename.txt r]
set line [gets $t]
if {[string match -nocase "*$text*" $line]} {
putquick "privmsg $chan $text is in the file!"
close $t
} else {
putquick "privmsg $chan $text isn't in the file!"
close $t
}
}
Isn't workin', how can we check a text if it is in the file? Like that,
<ZAL> !check Is it a problem?
<Egg> Is it a problem? < is in the file !
<ZAL> !check Is THAT a problem?
<Egg> Is THAT a problem? < is not in the file !
bind pub - !check check
proc check {nick uhost hand chan arg} {
global found
unset -nocomplain found 0
set what [join [lrange $arg 0 end]]
set fd [open filename r]
set cont [read $fd]
close $fd
foreach line [split $cont "\n"] {
if {[string match -nocase "*$what*" $line]} {
putserv "PRIVMSG $chan :'$what' is in the file!"
set found 1
}
}
if {![info exists found]} {
putserv "PRIVMSG $chan :Text is not found.."
}
}
There's no good reason to make the local process variable 'found' into a global variable.
It's never reused and forces us to unbind it to run the proc again.
Also 'arg' is not a list and shouldn't be handled like this... [join [lrange $arg 0 end]]
bind pub - !check check
proc check {nick uhost hand chan arg} {
set fd [open scripts/filename.txt r]
set cont [read $fd]
close $fd
foreach line [split $cont "\n"] {
if {[string match -nocase "*$arg*" $line]} {
putserv "PRIVMSG $chan :'$arg' is in the file!"
set found 1 ; break
}
}
if {![info exists found]} {
putserv "PRIVMSG $chan :Text is not found.."
}
}
Well i make the code as i know if i encouter problems in the future with codes i write then i modify the code.. but any modifications/improvment of my code is welcomed im always learning.. i also never used 'break'
bind pub - !check check
proc check {nick uhost hand chan text} {
set what [join [lrange $text 0 end]]
set fo [open "scripts/filename.txt" r]
set data [split [read $fo] "\n"]
close $fo
if {[lsearch -glob $data $what]} {
puthelp "PRIVMSG $chan :'$what' is in the file!"
} else {
puthelp "PRIVMSG $chan :Text is not found.."
}
}
PS: supports wildcards.
Once the game is over, the king and the pawn go back in the same box.