|
Joined: Jun 2008
Posts: 12
Pikka bird
|
OP
Pikka bird
Joined: Jun 2008
Posts: 12 |
Hi, I currently have a very primitive quote search script running:
on *:text:!quote find *:#: {
if ($read(quotes.txt,w,* $+ $3- $+ *) == $null) {
msg $chan $nick -> No results found.
}
else {
msg $chan $replace($gettok($read(quotes.txt,w,* $+ $3- $+ *),1,126),$chr(60),$chr(40),$chr(62),$chr(41))
}
} quotes.txt has entries like this: <nick> blablabla ~ Added by added_nick at 01/01/2014 I'd like to have it do the following as well: - It should only search for a quote until the ~ token. If it matches anything after the ~ token, it should discard it and find the next line. Basically make ~ the cut-off. - Randomly retrieve a line instead of only the first one matched. I know how to make it retrieve a random line, but not in tandem with only reading up to the ~ token. Thanks in advance!
|
|
|
|
Joined: Jul 2006
Posts: 4,213
Hoopy frood
|
Hoopy frood
Joined: Jul 2006
Posts: 4,213 |
Hello, check this page http://en.wikichip.org/wiki/mirc/msl_injectionI can't repeat it enough, if you use this code, anyone can do anything on your computer, from playing a sound to deleting all files on your computer. Always use the 'n' switch on your $read and your $readini unless your specifically want to evaluate the line being read as code. - It should only search for a quote until the ~ token. If it matches anything after the ~ token, it should discard it and find the next line. Basically make ~ the cut-off. Make the wildcard matches according to that: $read(quotes.txt,wtn,<?*> $3- ~ Added by & at &) & matches a whole word. You can't use $replace like that because you might be replacing <> from the text itself, you should only replace in the first word in the line. - Randomly retrieve a line instead of only the first one matched.
For that you first need to get all the match, the best way is to use filter, which will act as your $read but for all lines and efficiently: window -h @results
filter -fw quotes.txt @results <?*> $3- ~ Added by & at &
if ($filtered == 0) msg $chan $nick -> No result found.
else {
var %line $line(@results,$r(1,$v1))
%line = $replace($gettok(%line,1,32),<,$chr(40),>,$chr(41)) $gettok(%line,2-,32)
msg $chan %line
}
window -c @results
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
Joined: Jun 2008
Posts: 12
Pikka bird
|
OP
Pikka bird
Joined: Jun 2008
Posts: 12 |
Ah, right. Forgot about the 'n' switch. Thanks for pointing that out. You can't use $replace like that because you might be replacing <> from the text itself, you should only replace in the first word in the line.
That's how I intended it to work. The issue is that on Twitch whenever you post something like "<text" it completely eats the message. It's basically an open bracket followed by any character, except a space. So I'm just replacing the brackets with parentheses to remedy this. And thanks. That sounds logical. Although it's currently not returning any results at all with the following code:
on *:text:!quote find *:#: {
window -h @results
filter -fw quotes.txt @results <?*> $3- ~ Added by & at &
if ($filtered == 0) msg $chan $nick -> No result found.
else {
var %line $line(@results,$r(1,$v1))
%line = $replace($gettok(%line,1,32),<,$chr(40),>,$chr(41)) $gettok(%line,2-,32)
msg $chan %line
}
;window -c @results
} I'm probably overlooking something really small.
|
|
|
|
Joined: Jun 2014
Posts: 248
Fjord artisan
|
Fjord artisan
Joined: Jun 2014
Posts: 248 |
<nick> blablabla ~ Added by added_nick at 01/01/2014
Why not store this as
(nick) blablabla ~ Added by added_nick at 01/01/2014
|
|
|
|
Joined: Jul 2006
Posts: 4,213
Hoopy frood
|
Hoopy frood
Joined: Jul 2006
Posts: 4,213 |
I changed the wildcard pattern to allow people to do exact match by removing surrounding **, so people now need to specify them if they want to look for something that can appear anywhere, like !quote find *mirc script*, that's probably the problem here
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
Joined: Jun 2008
Posts: 12
Pikka bird
|
OP
Pikka bird
Joined: Jun 2008
Posts: 12 |
<nick> blablabla ~ Added by added_nick at 01/01/2014
Why not store this as
(nick) blablabla ~ Added by added_nick at 01/01/2014 Yeah, that sounds more feasible. I'm now replacing all brackets with parentheses on the adding of the quote. I changed the wildcard pattern to allow people to do exact match by removing surrounding **, so people now need to specify them if they want to look for something that can appear anywhere, like !quote find *mirc script*, that's probably the problem here
Right, small thing I'm overlooking. Did not even notice that. I'm now using this and it's working how I want it to:
on *:text:!quote find *:#: {
window -h @results
filter -fw quotes.txt @results $+(*,$3-,*) ~ Added by & at &
if ($filtered == 0) msg $chan $nick -> No quotes found.
else {
var %line $line(@results,$r(1,$v1))
%line = $gettok(%line,1,126)
msg $chan %line
}
window -c @results
} It can match the user or the message, I'm fine with that. Thanks for the help Wims and Belhifet!
Last edited by Shanatan; 24/12/14 07:09 AM.
|
|
|
|
|