mIRC Homepage
Posted By: goth80 filter file based on keywords then manipulate - 12/08/05 08:13 PM
Have file with data that always begins with a "nick" before the data separated by spaces i.e, "bobby246 You have been randomly selected for suchandsuch and soinforth for whatsathing."

Need to extract multiple lines beginning with a particular nick to msg to nick. i.e,
bobby246 You your wife is leaving you
bobby246 I dont like your pink shirt
bobby246 you really could use deodorant more

note: only in begining of line) not filter

diannaLee I really like bobby246 he wears them nice pink shirts and his wife is leaving him

Code:
 

on *:join:#: {
if ($lines(thatfile.txt) != 0) {
filter -ff thatfile.txt thisfile2.txt $nick $+ *
}
  var %x = 1, %lines = $lines(thisfile2.txt)  
  while (%x <= $lines(thisfile2.txt) {  
    msg $nick $read(thisfile2.txt,%x)
    inc %x  
  }
}



 
This will match all data for $nick and message them with it all.

Code:
On !*:join:#: {
  var %x = 1, %lines = $lines(thatfile.txt)
  while (%x <= %lines) {
    if ($nick isin $read(thatfile.txt,%x)) {
      msg $nick $gettok($read(thatfile.txt,%),2-,32)
    }
    inc %x
  }
}


This will match all data and message them with a random one and then unset the var.

Code:
On !*:join:#: {
  var %x = 1, %lines = $lines(thatfile.txt)
  while (%x <= %lines) {
    if ($nick isin $read(thatfile.txt,%x)) {
      %rand = $addtok(%rand,$gettok($read(thatfile.txt,%),2-,32),33)
    }
    inc %x
  }
  msg $nick $gettok(%rand,$rand(1,$numtok(%rand,33)),33)
  unset %rand
}


Hope this is what you meant.

-Andy
I wanted to msg all the match and extract/msg all the lines that started with the nick/text that began the line.

But as always thats for the effort, I undoubtedly will be able to learn from that and use it elsewhere.

aah an edit: but after looking at you're approach to it, after some sleep, I should be able to decipher how to acheive my goal.
There was a slight error with the first one:

Code:
On !*:join:#: {
  var %x = 1, %lines = $lines(thatfile.txt)
  while (%x <= %lines) {
    if ($nick isin $read(thatfile.txt,%x)) {
      msg $nick $gettok($read(thatfile.txt,%x),2-,32)
    }
    inc %x
  }
}


-Andy
/help /filter

//filter -fk file.txt myalias nickname *

alias myalias {
echo -a incoming line: $1
; your code
}
Outstanding!!

Worked like a ummmm __________(fill in some over used cliche) i.e, charm...

Though it would return all lines with the nick in it, it was a simple thing to resuse the gettok portion of your solution to reference the first word only.

Code:
 

On !*:join:#: {
  var %x = 1, %lines = $lines(thatfile.txt)
  while (%x <= %lines) {
    if ($nick isin $gettok($read(thatfile.txt,%x),1,32)) {
      msg $nick $gettok($read(thatfile.txt,%x),2-,32)
    }
    inc %x
  }
} 


Did I say it worked like a charm? Certainly I did... Much thanks to SladeKraven and all who helped (or will).
It'd be better if you used:

Code:
if ($nick [color:blue]==[/color] $gettok($read(thatfile.txt,%x),1,32)) {


-Andy
Tried to slow down the messaging with a timer slowed the initial posting of messages but they all came out at the same time. Cant the lines be messaged 1 at a time with delay between posting ?

Code:

 

On !*:join:#: {
  var %x = 1, %lines = $lines(thatfile.txt)
  while (%x <= %lines) {
    if ($nick isin $gettok($read(thatfile.txt,%x),1,32)) {
      .timer $+ %x 1 4 msg $nick $gettok($read(thatfile.txt,%x),2-,32)
    }
    inc %x
  }
} 

Code:
.timer 1 %x msg $nick $gettok($read(thatfile.txt,%x),2-,32)


-Andy
Are you even reading my post?

The perfect solution for this kind of thing, would be to filter the results to a temporary text file, which can be done in one small single command (/filter), and then /play the text file to the person or channel, with a specified delay to your liking, and a whole bunch of flags that come with /play to customize everything.

/help /filter
/help /play

Oh yeah, did I mention /filter is far superior to looping through a text file with $read?
Missed your post FiberOPtics (sleep deprived)... sounds like an excellent solution. I'll get some sleep go over filters again (did i say i was sleep deprived)., and give it a go later.

Thanks for the input
Without filter:
Code:
On !*:join:#: {
    var %i = i,%l = $lines(thefile.txt), %q = 0
    while (%i <= %l) {
        var %f = $read(thefile.txt,n,%i)
        var %n = $gettok(%f,1,32)
        var %m = $gettok(%f,2-,32)
        if (%n == $nick) {
            .timer -m 1 $calc(%q * 300) msg $chan %m
            inc %q
       }
    inc %i
    }
}

With filter:
Code:
On !*:join:#: {
    filter -ff thefile.txt _temp * $+ $nick
    var %i = 1
   while ($read(_temp,n,%i)) { .timer 1 $calc(%i * 300) msg $chan $gettok($ifmatch,2-,32) | inc %i }
   .remove _temp
} 
No need for the timers. /help play.

Play also offers you the advantage that the file is buffered to memory, so that it does not have to do repeated disk access, like your filter example where you loop with $read.

Btw you forgot the -m flag in your second example, it would only message each 5 minutes now.

Also, for someone that seems to be very worried about exploits and such, you have a big exploit in your code right there. Parameters passed to a timer are evaluated twice, once when passing them to the timer command, and once when the timer triggers.

A person could have said something in a quote that makes mIRC execute commands, like | exit.
Grr... ok then.. here's with play:
Code:
On !*:join:#: {

    filter -ff thefile.txt _temp * $+ $nick

    var %i = 1

    play -a interpret $chan _temp 300

   .remove _temp

} 

alias -l interpret { msg $1 $3- }
was generating this error: weird

/play: unable to open 'C:\Program Files\mIRC\_temp' (line 11, script7.mrc)

moved the wildcard after the $nick and it works perfectly...

Mucho thanks stefys99 for the great support

It would help greatly if you could comment the logic of the code. Even after studing the /help /filter I still dont understand all of how the code accomplishes what it does.
Sorry.. my foul.. should be $nick $+ * smile.. but you should also do a
Code:
if (!$exists(_temp)) { msg $chan No matches. | halt }
© mIRC Discussion Forums