mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jul 2005
Posts: 29
G
goth80 Offline OP
Ameglian cow
OP Offline
Ameglian cow
G
Joined: Jul 2005
Posts: 29
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  
  }
}



 


Whats life without a little Karma?
maddkarma[dot]com
Joined: Dec 2002
Posts: 3,547
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
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

Joined: Jul 2005
Posts: 29
G
goth80 Offline OP
Ameglian cow
OP Offline
Ameglian cow
G
Joined: Jul 2005
Posts: 29
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.

Last edited by goth80; 12/08/05 09:17 PM.
Joined: Dec 2002
Posts: 3,547
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
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

Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
/help /filter

//filter -fk file.txt myalias nickname *

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


Gone.
Joined: Jul 2005
Posts: 29
G
goth80 Offline OP
Ameglian cow
OP Offline
Ameglian cow
G
Joined: Jul 2005
Posts: 29
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).


Whats life without a little Karma?
maddkarma[dot]com
Joined: Dec 2002
Posts: 3,547
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
It'd be better if you used:

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


-Andy

Joined: Jul 2005
Posts: 29
G
goth80 Offline OP
Ameglian cow
OP Offline
Ameglian cow
G
Joined: Jul 2005
Posts: 29
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
  }
} 



Whats life without a little Karma?
maddkarma[dot]com
Joined: Dec 2002
Posts: 3,547
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
Code:
.timer 1 %x msg $nick $gettok($read(thatfile.txt,%x),2-,32)


-Andy

Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
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?


Gone.
Joined: Jul 2005
Posts: 29
G
goth80 Offline OP
Ameglian cow
OP Offline
Ameglian cow
G
Joined: Jul 2005
Posts: 29
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


Whats life without a little Karma?
maddkarma[dot]com
Joined: Aug 2005
Posts: 128
S
Vogon poet
Offline
Vogon poet
S
Joined: Aug 2005
Posts: 128
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
} 

Last edited by stefys99; 13/08/05 12:15 AM.
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
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.


Gone.
Joined: Aug 2005
Posts: 128
S
Vogon poet
Offline
Vogon poet
S
Joined: Aug 2005
Posts: 128
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- }

Joined: Jul 2005
Posts: 29
G
goth80 Offline OP
Ameglian cow
OP Offline
Ameglian cow
G
Joined: Jul 2005
Posts: 29
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.

Last edited by goth80; 13/08/05 01:40 AM.

Whats life without a little Karma?
maddkarma[dot]com
Joined: Aug 2005
Posts: 128
S
Vogon poet
Offline
Vogon poet
S
Joined: Aug 2005
Posts: 128
Sorry.. my foul.. should be $nick $+ * smile.. but you should also do a
Code:
if (!$exists(_temp)) { msg $chan No matches. | halt }


Link Copied to Clipboard