mIRC Home    About    Download    Register    News    Help

Print Thread
Page 1 of 2 1 2
Joined: Jul 2006
Posts: 248
B
bwuser Offline OP
Fjord artisan
OP Offline
Fjord artisan
B
Joined: Jul 2006
Posts: 248
im wondering if there is a way to read variables for isin from a .txt
seeing i have alot of things to match
so if it mathes one of the lines in my .txt (partially)
i want it to continue

so on the THIS.THING part in the code below
i want it to read from a .txt and partially match any line in there
so if it matches a line ie if the entire line is in the $1- (or more offcourse)
i want it to match

so 'Blah.Blah' is in my .txt
i want it to match that to Blah.Blah.Blah.Blah in $1-

and the txt contains the BEGINNING of what i what to match
so its always the beginning of a piece i dont want it to match if its like this 'nothing.nothing.Blah.Blah.Nothing'
so only 'Blah.Blah.Nothing'

i hope this is enough explanation

thanks in advance



Code:
ON 1: TEXT:*:# {
  if ($nick isin %TEST) {
    set %testnick $nick
    set %match $strip($1-)

    if (match1 isin %match) && (match2 isin %match) {
      if (match3 isin %match) || (match4 isin %match) { 
        if (THIS.THING isin %match) { .echo works}
      }
    }

    unset %testnick
    unset %match
  }
  else {
    halt
  }
}
 

Last edited by bwuser; 13/10/06 04:42 PM.
Joined: Dec 2002
Posts: 1,245
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
you left off a :

ON 1:TEXT:*:# {

should be

ON 1:TEXT:*:#: {

Joined: Jul 2006
Posts: 248
B
bwuser Offline OP
Fjord artisan
OP Offline
Fjord artisan
B
Joined: Jul 2006
Posts: 248
well it works fine like this as well
but you didnt even bother to read my question.

Joined: Dec 2002
Posts: 1,245
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
so if $strip($1) == match1

you could have it loop through to find the first match1

so if (match1 && match2) && (match3 || match4)
loop through the line til match1 using tokens and when it matches you get the token from that position to the end (which is what i guess you want)

Joined: Jul 2006
Posts: 248
B
bwuser Offline OP
Fjord artisan
OP Offline
Fjord artisan
B
Joined: Jul 2006
Posts: 248
no i want what i described
read from a .txt
and match to a line from it if the full line from the txt
matches a part of the one that is said on irc
ie replace the ' if (THIS.THING isin %match) ' part
with a $read command or whatever is needed to achieve it
i only want a PARTIAL match
so lets say i see this on irc :
-
<nickname> match1 match2 match3 match4 Blah.Blah.Go.Nuts.Test
-
and my .txt contains a line that says 'Blah.Blah'
it should match that
and go to action

Joined: Dec 2002
Posts: 1,245
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
Code:
ON 1:TEXT:*:#: {
  if ($nick isin %TEST) {
    set %testnick $nick
    set %match $strip($1-)
    if (match1 isin %match) &amp;&amp; (match2 isin %match) {
      if (match3 isin %match) || (match4 isin %match) { 

        if (THIS.THING isin %match) { .echo $read(match.txt,1) }
        if (THAT.THING isin %match) { .echo $read(match.txt,2) }
        if (SOME.THING isin %match) { .echo $read(match.txt,3) }

      }
    }
    unset %testnick
    unset %match
  }
}


I think thats what you asked, you are using triggers (this.thing) to select an optional event
such as reading line so and so
since you know the trigger and what you where it is in the text you shouldnt have to search for it
msg $chan $read(match.txt,1)
for example if line 1 had Choo Choo said the train if all your checks of matching text were in the line said in channel you would say "Choo Choo said the train"

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
I assume %TEST is already set somewhere? Otherwise, the script will do nothing.

From what I see as your description of what you want, I'd say that you want something like this:

Code:
on *:text:*:#: {
  if ($read(match.txt,s,$1-)) {
    msg $chan $read(match.txt,$readn)
  }
}


Now, keep in mind that this matches only if the all of the text is the beginning partial match. If you want to match it for any word in your string of text, then you'll want to use $istok and a loop. That will be a bit of a resource hog if you're going to read from a file that has many lines and if the text entered has many words.

Working Example:
<user> This is a partial match
<bot> This is a partial match of the whole line of text

Non-Working Example:
<user> Hello. This is a partial match

Unless "Hello." is included in the line in the text file, it won't trigger using the script I posted above.

Now, perhaps the best thing for you to use would be a hash file as it would not be a resource hog and you can set it up to handle many matches easily.

If you want to do something like that, then it would really help if you gave real examples rather than the made up "blah.blah" examples that aren't really very helpful. It is much easier to figure out what you are doing and help you do it the most efficient way if we have all the information and real examples of how you want it to work. Fake examples just being confusion into the script.


Invision Support
#Invision on irc.irchighway.net
Joined: Jul 2006
Posts: 248
B
bwuser Offline OP
Fjord artisan
OP Offline
Fjord artisan
B
Joined: Jul 2006
Posts: 248
ok im matching talkshows but they have dates and stuff and other weird things in the name.
for example :

David.Letterman.2006.10.11.Jon.Stewart
The.Daily.Show.10.09.2006
The.Colbert.Report.10.10.06

so i made a txt
with :
David.Letterman
The.Daily.Show
The.Colbert.Report

so if i see on irc 'The.Colbert.Report.10.10.06'
i'd like it to match to 'The.Colbert.Report'

so i can let my script make actions

Joined: Dec 2002
Posts: 1,245
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
[quote]
I assume %TEST is already set somewhere? Otherwise, the script will do nothing.[/qiote]

yes

Joined: Dec 2002
Posts: 1,245
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
did you try the scripting applied correctly to the input you are getting too see if it is doing what you requested

and as riamus2 indicated if %test is not set to (one suposses your nick?) it will not do anything as that if test will fail

Joined: Jul 2006
Posts: 248
B
bwuser Offline OP
Fjord artisan
OP Offline
Fjord artisan
B
Joined: Jul 2006
Posts: 248
rhiamus your script is not doing what i want it would work in the inverse way, but not like this
the irc thing supplies more information than the one in my .txt
hence it doesnt match

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Ok, I misunderstood. How about this? Note that it will only help when the text on IRC is formatted like "The.Daily.Show.10.09.2006", but won't work if there is more attached to the end of that, or if the date isn't 3 numbers. Without mIRC here, I can't play around with it too much and find a better way to do it. Actually, regex may be a better method, but I'm not any good at regex.

Code:
on *:text:*:#: {
  [color:green]; Check to see if the last 3 tokens (separated by .'s) are numbers.  If so, remove them.[/color]
  if ($remove($gettok($1,-3,44),.) isnum) { var %searchtext = $deltok($1,-3,44) }
  [color:green]; Check to see if there is a matching text in the file for the %searchtext variable.[/color]
  if ($read(match.txt,s,%searchtext)) {
      [color:green]; If so, display it to the channel.[/color]
    msg $chan $read(match.txt,$readn)
  }
}



Just a note... I don't have mIRC in front of me, or the help file and I would not be surprised if I messed something up in this script. Will someone who knows scripting check for errors for me? Thanks. smile


Invision Support
#Invision on irc.irchighway.net
Joined: Jul 2006
Posts: 248
B
bwuser Offline OP
Fjord artisan
OP Offline
Fjord artisan
B
Joined: Jul 2006
Posts: 248
i have a regex that can do that and make an exact match
but i really need a solution for something wtihout any constants
else i could use regex :x

hence my reason for using the blah example.
i am really only sure about the beginning
the end can have variable length/content etc

Last edited by bwuser; 13/10/06 10:28 PM.
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Well, another method that would work, but would put a bit of a load on your cpu would be to check the words one-by-one.

Code:
on *:text:*:#: {
  [color:green]; Only run if the first "word" includes 3+ tokens using .'s as separators.[/color]
  if ($gettok($1,0,44) &gt; 3) {
    [color:green]; This variable tracks the number of tokens we're checking.[/color]
    var %count = 0
    [color:green]; Keep checking until there is only one match.[/color]
    while (%results != 1) {
      [color:green]; If there are no matches, say so and exit.[/color]
      if (%results == 0) { echo -a No match. | return }
      inc %count
      [color:green]; If there isn't only 1 match after we finish checking all the tokens in the first word, return the error message and end.[/color]
      if (%count &gt; $gettok($1,0,44)) { echo -a No match. | return }
      [color:green]; Reset the results.[/color]
      var %results = 0
      [color:green]; This variable tracks the line numbers in your text file.[/color]
      var %count2 = 1
      [color:green]; Repeat until all lines are checked, or until the Break command is reached (see inside the while loop).[/color]
      while (%count &lt;= $lines(match.txt)) {
        [color:green]; If there is a match, increase the results variable.[/color]
        if ($gettok($1,%count,44) == $gettok($read(match.txt,%count2),%count,44)) { inc %results }
        [color:green]; If there is more than one match, break out of the loop.  This avoids checking the entire file when we already know we have more than one match.[/color]
        if (%results &gt; 1) { break }
        inc %count2
      }
    }
    [color:green]; Output the results once we only have a single match.[/color]
    msg $chan $read(match.txt,w,$gettok($1,%count,44) $+ *)
  }
}


Ok, again, I didn't test this. But, I am pretty sure it is correct. Keep in mind that it WILL be a resource hog if the text file has many lines. I've done what I could to limit how much CPU usage it will take up, but it's not a great method of doing this.

How this works:

<user> David.Letterman.10.11.2006

This will first search for David in the match.txt file. If there is only one line with David on it, it will output the results. Keep in mind that this may result in an incorrect output if you have some other David in your file and David.Letterman isn't in there. If there is more than one line with David, then it will search for David.Letterman in the file. Again, if there is only one result, that result will be displayed. If there is more than one line with David.Letterman on it, then it will do a search for David.Letterman.10 in the file. It will repeat this until there is either only 1 match or you run out of tokens in $1.

As long as your match.txt file includes all titles that you would want to search for, this should work. But, as I said in italics above, if you didn't have a David.Letterman line, but had some other David line, the wrong information would be displayed.

Reminder: This is not the best method as it uses the CPU more than you'd really want (assuming you have a lot of lines in the match.txt file). But, it should work until you have a better solution.

Joined: Jul 2006
Posts: 248
B
bwuser Offline OP
Fjord artisan
OP Offline
Fjord artisan
B
Joined: Jul 2006
Posts: 248
that looks like a weird way to solve this but im gonna check it out
what about hashtables?

Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
I didnt overly read everything above but i think your after this

Each time someone says something break it down into parts based on "." (tokenize on "." aka 46) and see if you file has any of them in it, your file lines need to match the front of but not the whole line said in channel.

ex
----- match.txt -----
fred.fries
john.boot
nick.alert.time
blah.blah
----- match.txt -----
Code:
fred.fries.1.2.3    [color:blue]MATCH[/color]
fred.fries&amp;cheese   [color:blue]NO MATCH[/color]
john                [color:blue]NO MATCH[/color]
john.boot           [color:blue]MATCH[/color]
nick.alert          [color:blue]NO MATCH[/color]
nick.alert.time.now [color:blue]MATCH[/color]
blah.blah.something [color:blue]MATCH[/color]
something.blah.blah [color:blue]NO MATCH[/color]


If this is what its ment to be this should do you.
Code:
;
;usage $isin.match.txt(&lt;text&gt;)
;returns $null = no match
;returns N = Line N of match.txt located at front of &lt;text&gt;
;
alias isin.match.txt {
  if ($isfile($+($scriptdir,match.txt))) {
    if (($file($+($scriptdir,match.txt)).mtime != %match.txt.file.mtime) || (!$hget(match.txt))) {
      set -se %match.txt.file.mtime $file($+($scriptdir,match.txt)).mtime
      hfree -w match.txt
      hmake    match.txt
      hload -n match.txt match.txt
    }
    var %c = 1 | while (%c &lt;= $numtok($1,46)) {
      if ($hfind(match.txt,$gettok($1,$+(1-,%c),46)).data) { return $v1 }
      inc %c
    }
  }
}



use in side your ON TEXT as per the example below...
if ($isin.match.txt($1-)) { echo -a MATCHED to line number $v1 }

** incase you want to know what its doing **
checks if the file exists,
then checks if the file has changed since the last time it was read into the hash table, or if the hash tables been deleted
then saves the last modified time of the file, and remakes the hashtable loading it with the file
then it takes the first token of the $1- (now all in $1) and looks for it in the hash table, if it finds it it returns with that value other wise gets the next token as well and checks again
keeps that up till it has compared the whole line and found no match, thus ends (any ending with out a RETURN returns $null)

Joined: Jun 2006
Posts: 508
D
Fjord artisan
Offline
Fjord artisan
D
Joined: Jun 2006
Posts: 508
Two methods using /filter.

/filter with hidden window
Code:
; Only trigger for token.token*
on $*:text:/^\S+\.\S/:%chan:{
  var %w = @match.words,%a = $gettok($1,1,46)
  ; If the first token is "The", add the second token.
  if %a == The { %a = $gettok($1,1-2,46) }
  window -h %w
  filter -fw match.txt %w $+(%a,*)
  if !$filtered { echo %chan No matches | window -c %w | return }
  var %i = 1,%z = No matches for
  while $line(%w,%i) {
    var %a = $v1
    if $+(%a,*) iswm $1 { var %z = Matched: %a to | break }
    inc %i
  }
  echo %chan %z $qt($1-)
  window -c %w
}

I didn't add more comments because it should be pretty self explanatory really smile

/filter with -k switch
Code:
on $*:text:/^\S+\.\S/:%chan:{
  var %a = $gettok($1,1,46)
  if %a == The { %a = $gettok($1,1-2,46) }
  set -u %$1 $1-
  filter -fk match.txt .matchtext $+(%a,*)
}
alias -l matchtext if $+($1,*) iswm %$1 { echo %chan $1 matched $qt($v2) }

Joined: Jul 2006
Posts: 248
B
bwuser Offline OP
Fjord artisan
OP Offline
Fjord artisan
B
Joined: Jul 2006
Posts: 248
thanks for the replies people
i think DaveC's method is exactly what i need
gonna try and get it working now

THANKS!

Joined: Jul 2006
Posts: 248
B
bwuser Offline OP
Fjord artisan
OP Offline
Fjord artisan
B
Joined: Jul 2006
Posts: 248
ok i didnt get it working yet

ex
----- us.talkshow.txt -----
Conan.O.Brien
David.Letterman
Jay.Leno
Jimmy.Kimmel.Live
The.Colbert.Report
The.Daily.Show
----- us.talkshow.txt -----

Code:
 

David.Letterman.45.Special.Guest.Here-YES [color:blue] MATCH [/color] 
David [color:red] NO MATCH [/color]
The.Daily.Show.2006.23.12-TEST [color:blue] MATCH [/color] 
Daily.Show.2006.23.12-TEST [color:red] NO MATCH [/color]

 


i altered some things in the script :

Code:
 
alias us.talkshow.match {
  if ($isfile($+($scriptdir,us.talkshow.txt))) {
    if (($file($+($scriptdir,us.talkshow.txt)).mtime != %us.talkshow.txt.file.mtime) || (!$hget(us.talkshow.txt))) {
      set -se %us.talkshow.txt.file.mtime $file($+($scriptdir,us.talkshow.txt)).mtime
      hfree -w us.talkshow.txt
      hmake    us.talkshow.txt
      hload -n us.talkshow.txt us.talkshow.txt
    }
    var %c = 1 | while (%c &lt;= $numtok($1,46)) {
      if ($hfind(us.talkshow.txt,$gettok($1,$+(1-,%c),46)).data) { return $v1 }
      inc %c
    }
  }
}
 


also i'd like us.talkshow.txt to be located in mircdir\TVCheck\

thanks in advance for your time i really appreciate it.

/bwuser

Joined: Jul 2006
Posts: 248
B
bwuser Offline OP
Fjord artisan
OP Offline
Fjord artisan
B
Joined: Jul 2006
Posts: 248
i forgot an important example

Blah.The.Daily Show == NO MATCH
The.Daily.Show.Blah == MATCH

Page 1 of 2 1 2

Link Copied to Clipboard