This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

search script

Old posts that have not been replied to for several years.
Locked
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

search script

Post by Ofloo »

how can i make it search as well if i do this

@find test test1
in stead of @find test*test1
and also make it work if it's the other way arround
cause now it only finds the words if it's in the txt like this "test ... test1"
and if i would use @find test1 test it wouldn't give any results

oh also and how could i return an other msg if there is no search results
ive tryed

Code: Select all

if {$cnt == 0} {
  ...
} else {
  ...
}
return 0
}
full script ;)

Code: Select all

bind PUB - @find find:pub

proc find:pub {nick uhost hand chan arg} {
  set srch [lindex $arg 0]
  set wfile [open "cnt.txt" "w"]
  puts -nonewline $wfile 0
  close $wfile
  putserv "PRIVMSG $nick :Searching for $srch"
  set fs [open "search.txt" r]
  while {![eof $fs]} {
    gets $fs line
    set sline [string tolower $line]
    if {[string match *$srch* $sline] == 1} {
      set rfile [open "cnt.txt" "r"]
      set rcnt [read $rfile]
      close $rfile
      set count [expr $rcnt + 1]
      set wfile [open "cnt.txt" "w"]
      puts -nonewline $wfile $count
      close $wfile
      putserv "PRIVMSG $nick :$line"
    }
  }
  set rfile [open "cnt.txt" "r"]
  set cnt [read $rfile]
  close $rfile
  putserv "PRIVMSG $nick :Search complete found $cnt results" 
  return 0
}
XplaiN but think of me as stupid
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

Ofloo wrote:how can i make it search as well if i do this

@find test test1
in stead of @find test*test1
and also make it work if it's the other way arround
cause now it only finds the words if it's in the txt like this "test ... test1"
and if i would use @find test1 test it wouldn't give any results

oh also and how could i return an other msg if there is no search results
To make '@find a b' become '@find a*b' is as simple as replacing the spaces with *'s.

Your code fetch the first word of the argument string using 'lindex' :o , so typing '@find a b' would result in searching for '*a*' and typing '@find {' would cause an error.

Use the counter value to determine which message to display after completion (x matches / no matches)

Code: Select all

bind pub - @find find:pub
proc find:pub {n u h c a} {
  set a *[string map {" " *} $a]*
  putserv "PRIVMSG $n :Searching for $a"
  set i 0
  set f [open "search.txt"]
  while {[gets $f b]>-1} {
    if {[string match -nocase $a $b]} {
      incr i
      putserv "PRIVMSG $n :$b"
    }
  }
  close $f
  if {$i} {
    putserv "PRIVMSG $n :Search complete found $i result[expr {$i==1?"":"s"}]"
  } {
    putserv "PRIVMSG $n :No matches."
  }
}
You could (should?) of course lappend the matching lines to a variable inside the while-loop and check the number of matches before you msg the user (to prevent abuse). Then you could also get rid of the counter variable and use [llength the_list] to get the number.

btw: in your code, what's the point of all that "cnt.txt" reading/writing?
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

hmm cause i tryed set var "0" and then incr var but that didn't work so from this point i only get it to work if i cache a var to a txt i mean var counter i know its a crappy way but ... it works i solved all the rest only replacing the spaces by s .. ima read up on what you sad and answer back then cause at this point it seems logic but not entirly clear on how i will do it i know you put me in the write direction and its almost in front of me but now i just need to understand it ;) so let me go true the code ;) then ill answer the rest ;) still learing to code tcl hehe me n00b eh ;)
XplaiN but think of me as stupid
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

feel free to give pointers on the current script ;) so i can make it shorter or/and more functional tnx

Code: Select all

bind PUB - @find find:pub

proc find:pub {nick uhost hand chan arg} {
global ftppass0 ftplog0 ftpport
  if {[lindex $arg 0] == ""} {
    putserv "NOTICE $nick :Usage: @find <query*query*..>"
  } else {
    set pre "0"
    set MyIP "" 
    foreach a {a b c d e f g h i j k} { 
      catch { 
        set external [socket $a.root-servers.net 53] 
        set MyIP [lindex [fconfigure $external -sockname] 0] 
        close $external             
      } 
      if { ![string equal $MyIP ""] } { break } 
    }
    set index [open "|index.exe" "r+"]
    index:dirs
    set srch [lindex $arg 0]
    set wfile [open "cnt.txt" "w"]
    puts -nonewline $wfile 0
    close $wfile
    putquick "PRIVMSG $nick :\00314Searching for \0037$srch \00314plz be patient.."
    set fs [open "search.txt" r]
    while {![eof $fs]} {
      gets $fs line
      set sline [string tolower $line]
      if {[string match *$srch* $sline] == 1} {
        set rfile [open "cnt.txt" "r"]
        set rcnt [read $rfile]
        close $rfile
        set count [expr $rcnt + 1]
        set wfile [open "cnt.txt" "w"]
        puts -nonewline $wfile $count
        close $wfile
	set dline [file tail $line]
        putserv "PRIVMSG $nick :\00314Search result $count:\0037 $dline"
        set pre "1"
      }
    }
    set rfile [open "cnt.txt" "r"]
    set cnt [read $rfile]
    close $rfile
    putserv "PRIVMSG $nick :\00314Search complete found\0037 $cnt \00314results." 
    if {$pre == "1"} {
      putserv "PRIVMSG $nick :\00314FTPinfo:\0037 ftp://$ftplog0:$ftppass0@$MyIP:$ftpport/"
    }
   return 0
  }
}

proc index:dirs {} {
    set rfile [open "app.txt" "r"]
    set afile [open "search.txt" "w"]
    foreach line [split [read $rfile] \n] {
      puts $afile $line
    }
    close $rfile
    close $afile
    set rfile [open "mov.txt" "r"]
    set afile [open "search.txt" "a"]
    foreach line [split [read $rfile] \n] {
      puts $afile $line 
    }
    close $rfile
    close $afile
    set rfile [open "gme.txt" "r"]
    set afile [open "search.txt" "a"]
    foreach line [split [read $rfile] \n] {
      puts $afile $line
    }
    close $rfile
    close $afile
    set rfile [open "mp3.txt" "r"]
    set afile [open "search.txt" "a"]
    foreach line [split [read $rfile] \n] {
      puts $afile $line
    }
    close $rfile
    close $afile   
    set rfile [open "bks.txt" "r"]
    set afile [open "search.txt" "a"]
    foreach line [split [read $rfile] \n] {
      puts $afile $line
    }
    close $rfile
    close $afile
    putlog "\002The @find function is been used. All files are indexed\002"
}
XplaiN but think of me as stupid
User avatar
devilsoulblack
Halfop
Posts: 62
Joined: Wed Nov 19, 2003 9:18 pm
Location: Chile
Contact:

thnaks

Post by devilsoulblack »

nice
---------
Add [SOLVED] to the thread title if your issue has been.
Search - FAQ
Locked