mIRC Home    About    Download    Register    News    Help

Print Thread
#57983 27/10/03 06:10 PM
Joined: Sep 2003
Posts: 21
S
soulz Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Sep 2003
Posts: 21
Hi hos it goin, I am tempting to make a search command for a help script in one of my channels. The search is keyword based, and searches a text file for results. However the text file recently got a bit bigger for offering support. and I now need help to figure out how to make the search display more then one result seeing as some keywords people may use may return with more then one result. What I was using before.. the $read command...

on *:text:!trigger *:#: {
//echo -a $read(textfile.txt, w, $2)
if ($readn == 0) { /notice $nick No help topics match the keyword you are searching with. | goto done }
/notice $nick $read(textfile.txt, $readn)
:done { }
}

no longer works for the desired results.. If someone could help me out with this point me in the right direction that would be helpful thanks
confused smile


Dejavue is only proof that dreams really do come true.
#57984 27/10/03 07:58 PM
Joined: Feb 2003
Posts: 810
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Feb 2003
Posts: 810
Firstly, it would be safer to use the 'n' switch for $read, otherwise it would evaluate what's being read.
Secondly, you could use a loop, since you want more than 1 result. A fast thing would be to use the file handling functions (or maybe /filter, but I'll stay with the former ones).
Edit: I've left $1 instead of $2.. fixed now. It was from my tests before I posted the code here (meaning, it works)
Code:
on *:text:!trigger *:#:{
  if ($fopen(help)) .fclose help
  .fopen help textfile.txt
  [color:brown]:seek_until_eof
  .fseek -w help * $+ $2*
  if (!$fopen(help).eof) {
    notice $nick $fread(help)
    var %found = 1
    goto seek_until_eof
  }[/color]
  elseif (!%found) notice $nick No help topics match the keyword you are searching with.
  .fclose help
}
The main point here is the loop, I just thought that doing it with /f* and $f* functions would be better than a lot of $read's.
I didn't use /while because this was a "do...until" case. /while would check the end of file (eof) before the script would search for the trigger, and I needed it to search first and then check eof.

Last edited by cold; 27/10/03 08:03 PM.

* cold edits his posts 24/7
#57985 28/10/03 05:32 AM
Joined: Aug 2003
Posts: 1,831
I
Hoopy frood
Offline
Hoopy frood
I
Joined: Aug 2003
Posts: 1,831
I think it would be better to use /filter and /play rather than $read or $fread. /filter being faster, and play able to send multi messages/notices without flooding.
Code:
on *:text:!trigger *:#:{
  var %a = $ticks $+ .txt
  filter -ff textfile.txt %a $+(*,$2-,*)
  if $filtered { .play -n $nick %a 1000 | .remove %a }
  else notice $nick No help topics matching $+(",$2-,")
}

#57986 28/10/03 12:09 PM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Quote:
I didn't use /while because this was a "do...until" case. /while would check the end of file (eof) before the script would search for the trigger, and I needed it to search first and then check eof.

You can still use /while, in the same way we use /while in sockread loops:
Code:
  .fopen blah file.txt
  .fseek -w blah *bleh*
  while !$feof {
     dostuffwith $fread(blah)
    .fseek -w blah *bleh*
  }
  .fclose blah


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
#57987 28/10/03 04:35 PM
Joined: Feb 2003
Posts: 810
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Feb 2003
Posts: 810
I know I can, I didn't say I couldn't :tongue: but that's why /goto's and labels are there too.
By the way, I prefer not using /while in /sockread loops for the same reason (unless it becomes considerably faster when speed is much important).

Last edited by cold; 28/10/03 04:56 PM.

* cold edits his posts 24/7
#57988 28/10/03 05:14 PM
Joined: Feb 2003
Posts: 810
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Feb 2003
Posts: 810
Here's a non-flooding /f* version:
Code:
on *:text:!trigger *:#:{
  $iif($timer(.help), .timer.help. $+ $nick 1 $timer(.help).secs) _help $nick $1-
}
alias _help {
  ; $1 = nick, $2 = !trigger, $3 = match string
  if ($fopen(help)) .fclose help
  .fopen help textfile.txt
  :seek_until_eof
  .fseek -w help * $+ $3*
  var %found = 0
  if (!$fopen(help).eof) {
    inc %found
    .timer.help. $+ %found 1 %found notice $1 $fread(help)
    .timer.help 1 %found halt
    goto seek_until_eof
  }
  elseif (!%found) notice $nick No help topics match the keyword you are searching with.
  .fclose help
}


However, looking at how big this became, I must agree that /filter+/play offers a better method. Just don't forget to take a look at file handling functions..


* cold edits his posts 24/7

Link Copied to Clipboard