mIRC Home    About    Download    Register    News    Help

Print Thread
#192973 13/01/08 05:50 PM
Joined: Dec 2007
Posts: 4
P
Phen Offline OP
Self-satisified door
OP Offline
Self-satisified door
P
Joined: Dec 2007
Posts: 4
Ok this is for a bot, a user msg's text to search for in a .txt file on the bot's dir. and if the text the users enters is found in the .txt file it will /msg $nick the whole line of the .txt file. And it will search the whole .txt file and if multiple lines of text are found with the search item it will /msg the user all of them back to them.

An example:

User enters -
Code:
/msg bot search blah


Then the bot searches a .txt file for the text "blah" and on each line the text "blah" is found it will /msg $nick [whole line] and will do that for each line the text "blah" is found on.

Hope this makes sense and you can help me. grin

Joined: Apr 2006
Posts: 464
O
Fjord artisan
Offline
Fjord artisan
O
Joined: Apr 2006
Posts: 464
This should do it.

Code:
on *:TEXT:search *:?:{
  var %string = $2-
  var %file = filename.txt

  var %cnt = 1
  var %ttl = $lines(%file)
  while (%cnt <= %ttl) {
    var %temptext = $read(%file,%cnt)
    if (%string isin %temptext) { msg $nick %temptext }
    inc %cnt
  }
}


Just specify the filename in the line: var %file = xxx.txt

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Keep in mind that unless you put some protections into your script, you may get someone searching for something like "a" and making you flood the channel. Also, unless you use a timer or the /play command, you will flood yourself off of the network if you have more than 4-6 matches at once.


Invision Support
#Invision on irc.irchighway.net
Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
Like Riamus2 said, you should use some protection and also, a while isn't a good idea in this case, /filter is better :

on *:text:search *:?:filter -c filename.txt o.txt $+(*,$2-*) | play $nick o.txt | if ($exists(o.txt)) .remove o.txt




#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Dec 2007
Posts: 4
P
Phen Offline OP
Self-satisified door
OP Offline
Self-satisified door
P
Joined: Dec 2007
Posts: 4
Originally Posted By: Riamus2
Keep in mind that unless you put some protections into your script, you may get someone searching for something like "a" and making you flood the channel. Also, unless you use a timer or the /play command, you will flood yourself off of the network if you have more than 4-6 matches at once.


oh no worries it's for an on level command only grin
only certain people will have access to it.

Last edited by Phen; 13/01/08 09:58 PM.
Joined: Apr 2006
Posts: 464
O
Fjord artisan
Offline
Fjord artisan
O
Joined: Apr 2006
Posts: 464
People usually integrate the stuff they ask here, into their own scripts.
For sure you need protections, but there are many types of protection you could apply and he didnt ask for that.
I just showed one way of doing it.

And I didnt know the filter command was able to do that.
Looks quite efficient indeed, glad you demonstrated that.

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Originally Posted By: OrionsBelt
People usually integrate the stuff they ask here, into their own scripts.
For sure you need protections, but there are many types of protection you could apply and he didnt ask for that.
I just showed one way of doing it.


I wasn't saying anything bad about what you gave. I was just pointing it out to the OP (notice the reply wasn't to you) so he/she knows about the possible problems. smile


Invision Support
#Invision on irc.irchighway.net

Link Copied to Clipboard