mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jan 2008
Posts: 13
T
tessa1 Offline OP
Pikka bird
OP Offline
Pikka bird
T
Joined: Jan 2008
Posts: 13
Heya. Got some free time and wanted to make a simple script and there are a few stuff that i'm confused about.

Cant find any function in the help file about itterating a text string.
Lets say that we have " Today i went to the USA. It was awesome .."

And that i want to save the words "It was awesome" to a temp variable.

How do I itterate the text ?

Tried to assign a var %i =1 and then have a while loop that checks if $%i == It but that fails because of " $%i " as it doesn't refer to the word 1. There must be a way to do this similarly instead of having line and lines with code if $1 == It then... if $2 == It then.. etc


So.. what I want to do is search the text until it encounters "It" and then save "It" and the 2 following words to a temp variable so that I can get "It was awesome".

Thanks for any help !

Joined: Dec 2002
Posts: 503
B
Fjord artisan
Offline
Fjord artisan
B
Joined: Dec 2002
Posts: 503
There are a number of ways to do what you are asking.

The easiest to learn is $gettok(). To use your example, it would look something like this:

Code:
alias test1 {
  tokenize 32 Today I went to the USA.  It was awesome ..
  var %i = 1
  while ($gettok($1-, %i, 32)) {
    if ($v1 == it) {
      %yourtext = $v1 $gettok($1-, $+($calc(%i + 1), -, $calc(%i + 2)), 32)
      break
    }
    inc %i
  }
  echo -a Text found: %yourtext
}

The twisty way, trying to do what you were doing is to use $eval():

Code:
alias test2 {
  tokenize 32 Today I went to the USA.  It was awesome ..
  var %i = 1
  while ($eval($+($chr(36), %i), 2)) {
    if ($v1 == it) {
      %yourtext = $v1 $eval($+($chr(36), $calc(%i + 1)), 2) $eval($+($chr(36), $calc(%i + 2)), 2)
      break
    }
    inc %i
  }
  echo -a Text found: %yourtext
}

This method can also be achieved using evaluation brackets ([ and ]). I'd suggest avoiding them for the moment however. Most things they are used for can be done with $eval(), and the rest are probably out of your pay scale.. smile

Moving right along.

Perhaps the best way to find string patterns like this is the powerful regular expressions. These can be complicated, but when used right, they are very powerful.

Code:
alias test3 {
  tokenize 32 Today I went to the USA.  It was awesome ..
  if ($regex($1-, /(it \w+ \w+)/i)) {
    %yourtext = $regml(1)
  }
  echo -a Text found: %yourtext
}

Now, these ideas are just the tip of the iceberg.

Give us a few more specifics, and we'll be happy to help you in any way we can.

Joined: Jan 2008
Posts: 13
T
tessa1 Offline OP
Pikka bird
OP Offline
Pikka bird
T
Joined: Jan 2008
Posts: 13
Thanks that helped understanding. I guess the best way to write it would be to use regex.

What i plan on having the script is for primary reading the output stream of iroffer bots. They are on the exact form

bot : [check this video] [SB]Video_name_01[CRC].avi - /msg bot xdcc send 5
bot : [new] [SB]Video_name_01[h264][CRC].mp4 - /msg bot xdcc send 6
bot : [this one sucks] [MekkaM]Video_name2_05[h264][CRC].mp4 - /msg bot xdcc send 7

Where [SB] and [MekkamM] stand short for usually the encoder of the files. and the [CRC] is the crc of the file like [F0T6A58]

So instead of having to manually do this every time for certain listing I want it to auto match the strings and download (as the files are around 150mb and I and the bots are sitting on 30+mbit connections the transfers goes fast... in matter of seconds)


The plan is to :

Search the line for a certain string like "*/msg & xdcc send &". Then an if statement to see if the line has [SB]_Video_name_01[h264] in it and then do a /msg bot xdcc send 5 .

Problems: The videos come with several episodes. So I had planned to make a global variable for episode count and which is incremented each time it downloads a file (so that it doesn't re download if some other bot posts the same things in other channel).
Meaning i would have a variable Videoname_count which is used to make a string [SB]Video_name_Videoname_count[h264].avi compare it to the actual input and then msg the bot and increment the count.

Phew.. That's whats I basically want it to do...

Last edited by tessa1; 18/01/08 04:51 PM.
Joined: Dec 2002
Posts: 503
B
Fjord artisan
Offline
Fjord artisan
B
Joined: Dec 2002
Posts: 503
If you want to hard-wire it for a single series, then you can use something like:

Code:
ON $*:TEXT:/series_string_(\d+).*((msg|ctcp) \S+ xdcc send \d+)/:#channel: {
  echo -s :: Match of $regml(1) and $regml(2)
}

You can remember the values returned in $regml(1) and launch the command put into $regml(2).

Joined: Jan 2008
Posts: 13
T
tessa1 Offline OP
Pikka bird
OP Offline
Pikka bird
T
Joined: Jan 2008
Posts: 13
Than you that helped a lot. Now I can match the strings and perform the script as I intended.

Three question though...

ON $*:TEXT:/series_string_(\d+).*((msg|ctcp) \S+ xdcc send \d+)/:#channel: {
echo -s :: Match of $regml(1) and $regml(2)
}


What is the meaning of the / / in the ON $*:TEXT:/series_string_(\d+).*((msg|ctcp) \S+ xdcc send \d+)/:#channel: {

I now know that using /text/g with regex will make it count the occurrences of the word text and that /text/i will make it case sensitive as in your previous example... so what does just // mean as in ex. $regex(my little text, /little.t/)

Second question... Is there a difference between the * and the ? operator for regex since I cant find a case where one fails and the other succeeds on a same example.

And the third question is about this line of code

%count 55
if ($regex(Videoname_55, Videoname.(0* $+ [ %count ])))

if I do echo -a $regml(1) it will return 05 instead of 055...Why and how do I fix this ?

Thanks !

Last edited by tessa1; 19/01/08 08:02 PM.
Joined: Dec 2002
Posts: 503
B
Fjord artisan
Offline
Fjord artisan
B
Joined: Dec 2002
Posts: 503
1) The //'s in a regular expression are the pattern delimiters. The surround the pattern. All patterns in mIRC require them. That being said, if you use the 'm' option, you can use a different character:

Code:
//echo -a :: $regex(little text, m#li(tt.*\s)#) :: $regml(1)

2)* means 0-or-more, ? means 0-or-1.. of the previous atom:

Code:
//echo -a :: $regex(litttle text, /i(t*)/) :: $regml(1) ::
:: 1 :: ttt ::
//echo -a :: $regex(litttle text, /i(t?)/) :: $regml(1) ::
:: 1 :: t ::

3)
Code:
if ($regex(Videoname_55, /Videoname.(0* $+ %count $+ )/)) {

Joined: Jan 2008
Posts: 13
T
tessa1 Offline OP
Pikka bird
OP Offline
Pikka bird
T
Joined: Jan 2008
Posts: 13
Got everything working perfectly. Thank you Bekar for your time and good explanation.

Last edited by tessa1; 20/01/08 06:39 AM.

Link Copied to Clipboard