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 file

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
B
BigToe
Halfop
Posts: 99
Joined: Thu Dec 30, 2010 4:49 pm

Search file

Post by BigToe »

Hello all

I need a script that will return results based on its 'special' format.
A user will search through the file using a public command.
The results will be played to the user as a query with a timer to make sure the bot does not flood out.
If someone is currently receiving messages from the bot and someone else uses the search script - it will add him to a queue spot, will inform of the user what his spot is and when hes done with #1 he'll move to #2 in line and #3 in line and so on untill the queue is done.

The text file format is as follows... notice that it will only return results that match the search text in the Brackets:

(Wizard vs. Giant) Has +3 power.
(Wizard vs. Giant) Wizard Eats pie for breakfast
(Wizard vs. Giant) Knows how to clean his own house, unlike the Giant.
(Frog vs. Bird) Frog Needs atleast 4 meals a day
(Frog vs. Bird) Frog is as fast as the Wizard and two times faster than Bird.
(The Hamster vs. The Dog) The Dog is evil, the Hamster is not.
(The Hamster vs. The Dog) The Dog is hungry, the Hamster is not.

An example of how the script would work:

<User> !Stats Wizard
<Bot> (Wizard vs. Giant) Has +3 power.
<Bot> (Wizard vs. Giant) Eats pie for breakfast
<Bot> (Wizard vs. Giant) Knows how to clean his own house, unlike the Giant.
Notice it did NOT return the Frog vs. Bird stat that talks about the Wizard:

(Frog vs. Bird) Frog is as fast as the Wizard and two times faster than Bird.


Please help.
d
doggo
Halfop
Posts: 97
Joined: Tue Jan 05, 2010 7:53 am
Contact:

Post by doggo »

tested a little and seems to work ok for the search

Code: Select all

bind pub -|- !stats bigtoe:search

set database_file "/home/botty/bigtoe.db"

proc bigtoe:search {nick uhost hand chan text} {

global database_file

       set file [open $database_file r]
       set data [read $file]
       close $file
       set count 0

       foreach line [split $data \n] {

           if { [string match -nocase "(*$text*)*" "$line"] == 1 } {

       	utimer 2 [list putserv "privmsg $chan :$line"]
	     incr count

           }
       }

       if {$count == 0} { putserv "privmsg $chan :sorry $nick no stats found for \"$text\"";return }	

}
B
BigToe
Halfop
Posts: 99
Joined: Thu Dec 30, 2010 4:49 pm

Post by BigToe »

Thanks doggo, that script works well!

Any chance for a Queue list to inform people if they have to wait because the script is currently displaying messages elsewhere? (I've made this a privmsg $nick script)
B
BigToe
Halfop
Posts: 99
Joined: Thu Dec 30, 2010 4:49 pm

Post by BigToe »

I need a configuration for this script please.

I need that I can define in the script how many results it will display to the user (like a variable that can be set)

And then it will display the newest results (the newest results would be from the bottom of the text file to the top, i.e the last 3 results would be lets say lines 100, 115 and 118 and not something like lines 1, 5, 50)..
d
doggo
Halfop
Posts: 97
Joined: Tue Jan 05, 2010 7:53 am
Contact:

Post by doggo »

give this a go..

not tested on bot but should be ok

Code: Select all

bind pub -|- !stats bigtoe:search 

set database_file "/home/botty/bigtoe.db" 
set how_many "3"

proc bigtoe:search {nick uhost hand chan text} { 

global database_file how_many

       set file [open $database_file r] 
       set data [read $file] 
       close $file 
       set count 0 

       foreach line [split $data \n] { 

          if { [string match -nocase "(*$text*)*" "$line"] == 1 } { 

          utimer 2 [list putserv "privmsg $chan :$line"] 
          incr count 
          
          if {$count == $how_many} { break }

           } 
       } 

       if {$count == 0} { putserv "privmsg $chan :sorry $nick no stats found for \"$text\"";return }    

} 
B
BigToe
Halfop
Posts: 99
Joined: Thu Dec 30, 2010 4:49 pm

Post by BigToe »

Thanks doggo!
d
dirty
Halfop
Posts: 40
Joined: Fri Feb 08, 2013 2:33 pm
Location: Romania
Contact:

Post by dirty »

Here is something for the queue .. I haven`t tested it but it should work. Also changed from privmsg $chan to $nick

Code: Select all

bind pub -|- !stats bigtoe:search 

set database_file "/home/botty/bigtoe.db" 
set how_many "5" 

proc bigtoe:search {nick uhost hand chan text} { 
	global database_file how_many 
	
	if {[queuesize help] > 0} { 
		putquick "PRIVMSG $nick :Please be patient you have been added to the queue."
	}
	set file [open $database_file r] 
	set data [read $file] 
    close $file 
    set count 0 

    foreach line [split $data \n] { 
		if { [string match -nocase "(*$text*)*" "$line"] == 1 } { 
			puthelp "PRIVMSG $nick :$line"
			incr count 
			if {$count == $how_many} { break } 
		} 
    } 

	if {$count == 0} { putserv "privmsg $chan :sorry $nick no stats found for \"$text\"";return }    
}
come to the dark side.. I have cookies!
WwW.BotZone.TK
Post Reply