egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Search file

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
BigToe
Halfop


Joined: 30 Dec 2010
Posts: 99

PostPosted: Sat Oct 13, 2012 5:30 pm    Post subject: Search file Reply with quote

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:


Quote:

<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.
Back to top
View user's profile Send private message
doggo
Halfop


Joined: 05 Jan 2010
Posts: 97

PostPosted: Mon Oct 15, 2012 9:19 am    Post subject: Reply with quote

tested a little and seems to work ok for the search


Code:

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 }   

}

_________________
NON geeky!! http://gotcode4u.com/
Back to top
View user's profile Send private message Visit poster's website
BigToe
Halfop


Joined: 30 Dec 2010
Posts: 99

PostPosted: Thu Oct 18, 2012 9:14 am    Post subject: Reply with quote

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)
Back to top
View user's profile Send private message
BigToe
Halfop


Joined: 30 Dec 2010
Posts: 99

PostPosted: Fri Feb 15, 2013 9:13 am    Post subject: Reply with quote

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)..
Back to top
View user's profile Send private message
doggo
Halfop


Joined: 05 Jan 2010
Posts: 97

PostPosted: Fri Feb 15, 2013 10:13 am    Post subject: Reply with quote

give this a go..

not tested on bot but should be ok

Code:
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 }   

}

_________________
NON geeky!! http://gotcode4u.com/
Back to top
View user's profile Send private message Visit poster's website
BigToe
Halfop


Joined: 30 Dec 2010
Posts: 99

PostPosted: Thu Feb 21, 2013 5:05 am    Post subject: Reply with quote

Thanks doggo!
Back to top
View user's profile Send private message
dirty
Halfop


Joined: 08 Feb 2013
Posts: 40
Location: Romania

PostPosted: Thu Feb 21, 2013 7:40 am    Post subject: Reply with quote

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

Code:

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
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber