For that kind of matching and $read, a loop over all lines of the file is inevitable.
[...]
else {
; loop all lines of the file
var %n = 1
while ($read(text.txt,n,%n) != $null) {
; check for current line matching the third word
if ($v1 isin $3) {
; output and stop further processing in case of success
msg $chan message for line $v1 matching word $3
return
}
inc %n
}
; no success
msg $chan message for no match
}
Hash tables would allow you to search for both: any <data> matched by <wildtext> (like $read and w), and any <wilddata> matching <text> (what you're after).
Especially if you have a file with a lot of lines, the method outlined below should perform much better:
[...]
else {
; create hash table if it does not exist
if (!$hget(likefile)) { likefile.load }
; check for any hash table data wildmatching the third word (returns first match only)
if ($hfind(likefile,$3,1,W).data) { msg $chan data $hget(likefile,$v1) matches text $3 }
; no match
else { msg $chan message for no match }
}
[...]
}
; load file into a hash table
; hash table items will be a numerical index ("line number"), the content of each line the data for that item
alias likefile.load {
if ($hget(likefile)) { hfree likefile }
hmake likefile
hload -n likefile "text.txt"
}
Note that your text file now has to contain a list of words
with wildcards like *dog* or cat*
As you're not checking the file but the hash table, use the /likefile.load command after any modification of the textfile.