mIRC Homepage
Posted By: bwuser is it possible to read isin from a .txt - 13/10/06 04:37 PM
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
  }
}
 
Posted By: MikeChat Re: is it possible to read isin from a .txt - 13/10/06 05:50 PM
you left off a :

ON 1:TEXT:*:# {

should be

ON 1:TEXT:*:#: {
Posted By: bwuser Re: is it possible to read isin from a .txt - 13/10/06 05:59 PM
well it works fine like this as well
but you didnt even bother to read my question.
Posted By: MikeChat Re: is it possible to read isin from a .txt - 13/10/06 06:23 PM
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)
Posted By: bwuser Re: is it possible to read isin from a .txt - 13/10/06 06:38 PM
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
Posted By: MikeChat Re: is it possible to read isin from a .txt - 13/10/06 08:25 PM
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"
Posted By: Riamus2 Re: is it possible to read isin from a .txt - 13/10/06 08:52 PM
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.
Posted By: bwuser Re: is it possible to read isin from a .txt - 13/10/06 09:24 PM
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
Posted By: MikeChat Re: is it possible to read isin from a .txt - 13/10/06 09:35 PM
[quote]
I assume %TEST is already set somewhere? Otherwise, the script will do nothing.[/qiote]

yes
Posted By: MikeChat Re: is it possible to read isin from a .txt - 13/10/06 09:38 PM
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
Posted By: bwuser Re: is it possible to read isin from a .txt - 13/10/06 09:45 PM
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
Posted By: Riamus2 Re: is it possible to read isin from a .txt - 13/10/06 10:10 PM
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
Posted By: bwuser Re: is it possible to read isin from a .txt - 13/10/06 10:26 PM
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
Posted By: Riamus2 Re: is it possible to read isin from a .txt - 13/10/06 10:55 PM
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.
Posted By: bwuser Re: is it possible to read isin from a .txt - 13/10/06 11:22 PM
that looks like a weird way to solve this but im gonna check it out
what about hashtables?
Posted By: DaveC Re: is it possible to read isin from a .txt - 14/10/06 02:18 AM
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)
Posted By: deegee Re: is it possible to read isin from a .txt - 14/10/06 06:02 AM
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) }
Posted By: bwuser Re: is it possible to read isin from a .txt - 14/10/06 11:02 AM
thanks for the replies people
i think DaveC's method is exactly what i need
gonna try and get it working now

THANKS!
Posted By: bwuser Re: is it possible to read isin from a .txt - 14/10/06 11:26 AM
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
Posted By: bwuser Re: is it possible to read isin from a .txt - 14/10/06 01:50 PM
i forgot an important example

Blah.The.Daily Show == NO MATCH
The.Daily.Show.Blah == MATCH
Can you elaborate on what isn't working, and how you want it to work?

-genius_at_work
Posted By: bwuser Re: is it possible to read isin from a .txt - 14/10/06 05:15 PM
actually i made the error of putting the code in alias instead of remote.
yes dumb mistake smile
so i only would like to change location of the .txt in that script
to $scriptdir \TVCheck\

thanks
Posted By: Riamus2 Re: is it possible to read isin from a .txt - 14/10/06 06:56 PM
You know... if you want it to match anywhere in the line of text, or with/without various words (e.g. "the"), then you're really getting complicated.

Trying to make a script that will handle all combinations of filenames that people send of the various show episodes is an effort in futility because no matter how many exceptions you throw into the script, it's not an intelligent script. It will never be able to notice everything that you notice. Ok, so you decide to ignore "The" in the filename. What about when someone doesn't have "A" in the title? Ok, so you add that in there. What if people format it with - instead of .? Ok, you add that in. What if people put something else in front of the name?

Do you see where I am going with this? I suppose you could eventually find 99% of the possible ways the filenames will be formatted, but it will take quite awhile to find them all. Also, by the time you get them all working, it will probably have to search through the file/hash table/whatever so many times that it will be a waste of CPU to do so.

People ask for MP3 sorters all the time (same basic idea you want). It just isn't possible to make something that will catch all possibilities when you are getting filenames from different people because they will all format them differently.

Perhaps the best suggestion I'd give you would be to try and set up a multi-level system to check each "word" to.

file.txt
--
The
-The.Daily.Show
-The.Daily
-The.Colbert.Report
-The.Colbert

Colbert
-Colbert.Report

Daily
-Daily.Show
--

With this sort of structure, you could do a search for Daily. It would tell you that Daily.Show was a match, so you could see if .Show follows Daily. If so, it's a match. If not, it's not and you go on to the next.

If it started with The, then it would first check The.Daily.Show, if that's not a match, it would check The.Daily, if that's not a match, then it would continue down. If nothing matches, it would move on to the second part of the text (second token in $1).

This really is a very intensive process, but it may be the closest you'll get to 100% accuracy as it wouldn't hang up on missing words or extra words, as long as no words are inserted in the middle of the title.
Posted By: DaveC Re: is it possible to read isin from a .txt - 14/10/06 11:25 PM
Quote:
ex
----- us.talkshow.txt -----
Conan.O.Brien
David.Letterman
Jay.Leno
Jimmy.Kimmel.Live
The.Colbert.Report
The.Daily.Show
----- us.talkshow.txt -----
David.Letterman.45.Special.Guest.Here-YES MATCH
David NO MATCH
The.Daily.Show.2006.23.12-TEST MATCH
Daily.Show.2006.23.12-TEST NO MATCH
Blah.The.Daily Show == NO MATCH
The.Daily.Show.Blah == MATCH

There all correct, as per your direction, or at least as i understoodf what you said.

The text said in channel must be matched at the start of the text by a line in the file, beyond that there was no divinitive position.

Blah.The.Daily Show cant be matched becuase blah isnt on the front of any lines in the file
The.Daily.Show.Blah this is matched by line #6 in the file


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

replace
$+($scriptdir,us.talkshow.txt)
with
$+($mircdir,TVCheck\us.talkshow.txt)
© mIRC Discussion Forums