mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Dec 2003
Posts: 199
K
Vogon poet
OP Offline
Vogon poet
K
Joined: Dec 2003
Posts: 199
alias qsearch2 {
unset %quotes
var %x = 1
var %qsearch $1-
var %quotes 0
msg $active Searching For " $+ $1- $+ "
while (%x <= $lines(Quotes.txt)) { if (%qsearch isin $read(Quotes.txt,%x)) { inc %quotes | msg $active Result: $+ %quotes Quote: %x $+ / $+ $lines(Quotes.txt) $read(quotes.txt,%x) }
inc %x
}
msg $active There was %quotes found matching the text " $+ $1- $+ "
}
The "MSG $ACTIVE THERE WAS %QUOTES" ETC. part isn't working. Oops, Sorry, Stupid Caps Lock. =/
Anyhow, I'm stumped as to why it's not working... Any Suggestions?


Want to Link Servers? PM Me
- EliteIRC.dyndns.org -
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Hi,

looping through each line of that text file to check if the string is in the line is quite slow, and can be done more efficiently.

Perhaps try out this little snippet:
Code:
 
alias qsearch1 {
  var %string = $+(",$1-,")
  msg $active Searching for %string
  window -h @@ 
  filter -fwn quotes.txt @@ $+(*,$1-,*)
  var %a = 1, %b = $filtered, %c = $lines(quotes.txt)
  msg $active There were %b quotes found matching text %string out of %c lines.
  while (%a &lt;= %b) { tokenize 32 $line(@@,%a) | msg $active Quote $1 / %c --&gt; $2- | inc %a }
  window -c @@
}

It might look like more code, but it's faster than looping through the file, especially if you have a lot of quotes in your quotes.txt file. Note that you could get flooded off the server if there were too many matches, cuz mIRC will message all of them at once to the active window.

Knowing that, you could perhaps use /savebuf to save the filtered lines to a text file, and then use the /play command to play the matches to the active window, using an interval that won't flood you off.
Code:
 
alias qsearch2 {
  var %string = $+(",$1-,")
  msg $active Searching for %string
  window -h @@ 
  filter -fwn quotes.txt @@ $+(*,$1-,*)
  msg $active There were $filtered quotes found matching text %string out of $lines(quotes.txt) lines.  
  if $filtered { savebuf @@ quotes.tmp | play -a MsgQuote quotes.tmp [color:red]1000[/color] | .remove quotes.tmp }
  window -c @@
}
alias MsgQuote msg $1 Line $2 / $lines(quotes.txt) --&gt; $3- 

1.
The 1000 is the interval in milliseconds. Normally this shouldn't be added since 1000 is the default delay, but I added it anyway so that you can see where you can change it. So change that number to your likings.

2.
The /play command has more features which might be interesting for you, such as a queuing system. More information can be found by doing /help /play

3.
If you are planning on using this alias in an on TEXT event, where others can search for a quote, then it would be best to put the $active in a variable, so that the quotes are messaged to the correct window.

To illustrate my point:
You are in channels a and b, but active window is a.
Someone in b types !qsearch <quote> but since your active window is a, the quotes will be messaged to a, instead of b. Therefore you should put b in a variable (e.g. %q.target), and let the script msg to %q.target


Hope this was helpful,

Greets

Last edited by FiberOPtics; 17/06/04 11:57 AM.

Gone.
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Added note:

looking back at it, if you opt for the solution where the matches are saved to quotes.tmp, you don't even need the hidden window then, and filter straight to the temp file. It's also better not to have $lines(quotes.txt) evaluate with each line played to the channel. A global variable will do. (look at me correcting myself :tongue:)

Final code:
Code:
  
alias qsearch3 {
  %q.lines = $lines(quotes.txt)
  var %string = $+(",$1-,")
  msg $active Searching for %string
  filter -ffn quotes.txt quotes.tmp $+(*,$1-,*)
  msg $active Found $filtered quotes matching %string out of %q.lines lines.
  if $filtered { play -a MsgQuote quotes.tmp }
  .remove quotes.tmp 
}
alias MsgQuote msg $1 Line $2 / %q.lines --&gt; $3- 


Last edited by FiberOPtics; 17/06/04 05:18 PM.

Gone.
Joined: Dec 2003
Posts: 199
K
Vogon poet
OP Offline
Vogon poet
K
Joined: Dec 2003
Posts: 199
Yeah, I'm aware of the alternatives, But Can You also tell me how to fix MY code? laugh


Want to Link Servers? PM Me
- EliteIRC.dyndns.org -
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Hi,

your code doesn't need fixing because it's working fine. I've tested it (copy/paste) and it works as it should. I just gave you those alternatives because they are cleaner and faster.

This is your script in action:

[01:39] <Cellka> Searching For "ice"
[01:39] <Cellka> Result:1 Quote: 182/437 IceCold-IRC:irc.icecold-irc.net:6667
[01:39] <Cellka> Result:2 Quote: 426/437 Rizon:services.rizon.net
[01:39] <Cellka> There was 2 found matching the text "ice"

Greets


Gone.

Link Copied to Clipboard