We can do a little better than looping over the users text, or reading over the text file searching for matches.
Both are very slow as mIRC's while loops are slow, and file reads are even slower.
As wims stated, depending on how many words you have in the text file, you could simply use a single regex to match.
Since you stated your word list was quite large, that isn't an option. so what to do? Well, there is a solution that (1) Doesn't require looping, and (2) doesn't need file reads passed mIRC starting: hashtables with the use of $hfind().
Using either $hfind(..., W, 1) or $hfind(..., R, 1) mIRC will search the hashtable as though its items are the wildcard/regex text for us, being far faster than using mSL looping.
To use this, though, you'll need to convert your textfile.txt into a hashtable:
; converts the .txt file to a hashtable for use
; usage: /textfile2hashtable filepath/filename.txt
alias textfile2hashtable {
; if the hashtable 'word_list' doesn't exist, create it
if (!$hget(word_list)) {
hmake word_list 10
}
; get the number of lines for the file, create an illiterator variable, and a few tmp variables.
var %e = $lines($1-), %i = 0, %line, %item
; start looping
while (%i < %e) {
inc %i
; read the line from the text file
%line = $read($1-, nt, %n)
; sanitize the line read
%item = /\b\Q $+ $replace($1-, \, \\, $chr(32), \x20) $+ \E\b/i
; add the sanitized line to the hash table
hadd word_list %item %line
}
; once the looping is finished, save the hashtable
hsave word_list $filename(word_list.dat)
}
Once converted, we can modify wims's script to make use of it
; when mIRC stats, call /load_words
on *:START:{
load_words
}
; alias to load word_list.dat into an in-memory hashtable
alias load_words {
; free the hashtable if it exists
if ($hget(word_list)) hfree word_list
; create the hashtable
hmake word_list 10
; load entries from <scriptdir>/word_list.dat
hload world_list $qt($scriptdirword_list.dat)
}
; alias that adds words to the list
alias add_word {
; if the hashtable doesn't exist, create it
if (!$hget(word_list)) load_words
; store the 'word' in a variable
var %word = $1-
; store the 'word' under a sanitized version (/\b\Qword_here\E\b/i)
hadd -m word_list /\b\Q $+ $replace(%word, \, \\, $chr(32), \x20) $+ \E\b/i %word
; save the hashtable
hsave -o word_list $qt($scriptdirword_list.dat)
}
; alias to remove words from the list
alias del_word {
; if the hashtable doesn't exist, load the word_list
if (!$hget(word_list)) load_words
; remove the sanitized version of the word from the hashtable
hdel word_list /\b\Q $+ $replace($1-, \, \\, $chr(32), \x20) $+ \E\b/i
; save the hashtable
hsave -o word_list $qt($scriptdirword_list.dat)
}
; on text event
on *:TEXT:*:#:{
; search the hashtable for a match
if ($hfind(word_list, R, 1)) {
;; text found
}
}