mIRC Homepage
Posted By: Phen Searching a file help - 13/01/08 05:50 PM
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
Posted By: OrionsBelt Re: Searching a file help - 13/01/08 07:40 PM
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
Posted By: Riamus2 Re: Searching a file help - 13/01/08 09:28 PM
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.
Posted By: Wims Re: Searching a file help - 13/01/08 09:54 PM
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


Posted By: Phen Re: Searching a file help - 13/01/08 09:58 PM
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.
Posted By: OrionsBelt Re: Searching a file help - 13/01/08 10:11 PM
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.
Posted By: Riamus2 Re: Searching a file help - 14/01/08 11:08 AM
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
© mIRC Discussion Forums