mIRC Home    About    Download    Register    News    Help

Print Thread
Page 1 of 2 1 2
#269866 08/02/22 05:51 PM
Joined: Feb 2022
Posts: 12
P
Pikka bird
OP Offline
Pikka bird
P
Joined: Feb 2022
Posts: 12
Hello. I'm new to scripting and need help with a modest script I made below, please. It's working, but it's not doing exactly what I want which is to trigger ONLY when the said text FULLY matches what is in .txt file.

For example, let's say I have the line "What is the color of an apple?" in a .txt file. I DON'T want the script to trigger on "color of an apple?" or "an apple?" or "apple?" etc, but ONLY if it matches EXACTLY (word for word, including spaces) the sentence "What is the color of an apple?" from the .txt file, with not a character more or less. In other words, I want it to trigger ONLY on a %100 match.

I've tried reading a lot, but it's too complicated for me. Here's what I have:

on *:TEXT:*:#:{
var %WhatWasSaid = $1-
if ($read(QA.txt,w,$+(*,%WhatWasSaid ,*)) != $null) {do something}
}


Joined: Jan 2012
Posts: 289
Fjord artisan
Offline
Fjord artisan
Joined: Jan 2012
Posts: 289
Code
on *:TEXT:*:#:{
  var %msg1 $strip($1-) | var %msg2 $+(*,%msg1,*) | var %file QA.txt
  if ($read(%file,-nw,%msg2)) {
    var %num $readn | var %str $+(*,$read(%file,-n,%num),*)
    if (%str iswmcs %msg1) { msg $chan 04Line %num 12- there is a 100% match. }
  }
}


🌐 http://forum.epicnet.ru πŸ“œ irc.epicnet.ru 6667 #Code | mIRC scripts, help, discuss, examples
Joined: Feb 2022
Posts: 12
P
Pikka bird
OP Offline
Pikka bird
P
Joined: Feb 2022
Posts: 12
Hello and thanks for replying, Epic.

I copied and pasted your code to test it and nothing happened. confused

If I add the "w" switch, though, to your 4th line

var %num $readn | var %str $+(*,$read(%file,-nw,%num),*)

it then works, but it's back to doing the same thing: responding to all of the below texts (even without the question mark)

What is the capital of Germany?
is the capital of Germany?
the capital of Germany?
capital of Germany?
of Germany?
Germany?

I want it to trigger ONLY on the first line from the QA.txt, which is What is the capital of Germany?

Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
You're both adding * to the string when you should not be if you want an exact match

Epic #269871 09/02/22 09:42 PM
Joined: Feb 2022
Posts: 12
P
Pikka bird
OP Offline
Pikka bird
P
Joined: Feb 2022
Posts: 12
You are truly epic, Epic. Thanks a lot! smile I got it working after changing iswmcs to iswm in the 5th line of the code you gave me:

Code
(%str iswmcs %msg1) { msg $chan 04Line %num 12- there is a 100% match. }


Not sure why iswmcs isn't working. Nothing happens. But as soon as I changed that to iswm, the script works fine and just as I wanted. Thanks again!

Joined: Jul 2006
Posts: 4,134
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,134
The n switch on $read and other switches on $read and $readini (but all identifiers' switches in general) do not take the dash character before them, unsure if the dash is ignored and it still work or not.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Feb 2015
Posts: 138
kap Offline
Vogon poet
Offline
Vogon poet
Joined: Feb 2015
Posts: 138
FYI - Thought I'd put it out there...

This is pai's old pnp code that I checked a few years ago under mIRC 7.x and afaik still works:

https://github.com/peace-and-protec...6840eac0b7/pnp-spellchk/spellchk.mrc#L39

Caveat: Haven't checked it now, not sure if it's still working...


GNU Terry Pratchett - Looking for a mIRC help channel -> Check #mircscripting @ irc.swiftirc.net
Joined: Jan 2012
Posts: 289
Fjord artisan
Offline
Fjord artisan
Joined: Jan 2012
Posts: 289
All script codes that I publish here made and are pre-tested by me personally, therefore most often are working correct. If something doesn’t work for you, then 99,9% you did something wrong.

Code
if (%str iswmcs %msg1) { ... }

    iswm - returns true, if string with wildcards * in a variable %str matches string in a variable %msg1.
    iswmcs - returns true, if string with wildcards * in a variable %str matches (case sensitive) string in a variable %msg1.

Information about comparison operators: https://en.wikichip.org/wiki/mirc/operators
Information about switches in the read identifier: https://en.wikichip.org/wiki/mirc/identifiers/$read

Since you only wanted to get a 100% match, I used a more precise comparison operator "iswmcs" so that even the case of letters in the text matches (with different height): "А != а".

For example, a message: "What is the capital of Germany?" - will not be the same as: "what is the capital of germany?".

Therefore, if the letter case of the message on the channel differs from the case of letters in the text from the file, then you will not get any result.


If you do not need this, then can use a simpler code:
Code
on *:TEXT:*:#:{
  var %msg1 $strip($1-) | var %file QA.txt
  if ($read(%file,-nw,%msg1)) {
    var %num $readn | var %str $read(%file,-n,%num)
    if (%str == %msg1) { msg $chan 04Line %num 12- there is a 99% match. }
  }
}

Or even code like this:
Code
on *:TEXT:*:#:{
  var %msg1 $strip($1-) | var %file QA.txt
  if ($read(%file,-nw,%msg1)) { msg $chan 04Line $readn 12- there is a 99% match. }
}

Or even easier:
Code
on *:TEXT:*:#: if ($read(QA.txt,-nw,$1-)) msg $chan 04Line $readn 12- there is a 98% match.


Probably with this code variant there will be the most accurate text check:
Code
on *:TEXT:*:#:{
  var %msg $strip($1-) | var %file QA.txt
  if ($read(%file,-nw,%msg)) {
    var %num $readn | var %str $read(%file,-n,%num)
    if (%str isincs %msg && $len(%str) == $len(%msg)) {   
      msg $chan 04Line %num 12- there is a 100% match.
    }
  }
}


Last edited by Epic; 10/02/22 02:20 PM. Reason: Making changes to the post of new details, examples and scripts

🌐 http://forum.epicnet.ru πŸ“œ irc.epicnet.ru 6667 #Code | mIRC scripts, help, discuss, examples
Joined: Jul 2006
Posts: 4,134
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,134
The n switch on $read and other switches on $read and $readini (but all identifiers' switches in general) do not take the dash character before them, unsure if the dash is ignored and it still work or not.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Jul 2006
Posts: 4,134
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,134
This line 39 is using the old format of identifiers, which is awful and has been replaced by parenthesis identifier, old format do take the dash.

Last edited by Wims; 10/02/22 06:10 PM.

#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Jan 2012
Posts: 289
Fjord artisan
Offline
Fjord artisan
Joined: Jan 2012
Posts: 289
Originally Posted by Wims
The n switch on $read and other switches on $read and $readini (but all identifiers' switches in general) do not take the dash character before them, unsure if the dash is ignored and it still work or not.

Quite right. Adding a dash next to the "-nw" switches in a identifier $read is the older way, but this does not affect negatively the operation of the identifier in any way.

According to my observations during testing: "$read(file.txt, -nw, match)" or "$read(file.txt, nw, match)" - both examples works the equally.

In this case, it's an old habit of mine, and i like that more, how the switches stand out visually better in a line of code. However, it is of course recommended to use the new standard without dashes.



🌐 http://forum.epicnet.ru πŸ“œ irc.epicnet.ru 6667 #Code | mIRC scripts, help, discuss, examples
Joined: Jul 2006
Posts: 4,134
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,134
Were you scripting back in the days when that syntax was used?
Well I'm not sure how error prone it can be or if it will ever backfire, but I don't like that dash in there.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Feb 2022
Posts: 12
P
Pikka bird
OP Offline
Pikka bird
P
Joined: Feb 2022
Posts: 12
Thank you very much, Epic. I appreciate the time you put into responding and helping me. Everything works fine now. Thanks again! smile

Epic #269928 17/02/22 05:02 PM
Joined: Feb 2022
Posts: 12
P
Pikka bird
OP Offline
Pikka bird
P
Joined: Feb 2022
Posts: 12
Hello, Epic. I wonder if I could ask you for one more thing.

I''m pretty much done with a Trivia script I'm setting up, thanks to your last tip on how to handle the text match. Everything's working fine now, except for one last thing which my novice brain cannot understand. I've spent the last 4 days searching and trying to learn how to do it so I don't bother people with what might be perhaps a newbie question, but to be honest, it's just way too complicated for me to grasp. And that's how to create a hint system from the %answer variable.

My trivia bot reads from a txt file a question and an answer which are then populated into %question and %answer variables using $read and $gettok. So far so good.

For example: Who is the founder of Micrsoft?|Bill Gates

Timer1 1 10 Who is the founder of Microsoft?
Timer2 1 20 Hint: **** *****
Timer3 1 30 B*** G****
Timer4 1 40 B**l G**e*
Timer5 1 50 Bill Gates

I've succeeded with timer 1 and timer 5 and everything else in the entire script apart from the hint system, which basically is timer 2 , 3 and 4. How can I asterisk everything on the first hint, and then on the second and third hints give out random letters depending on total count of characters? For example 10% hint if total character count of %answer is 5 letters, 20% if it's 10 letters, etc. Doesn't matter, really. Just an example. Any number will do. Just giving you an idea.

I've read about creating a separate hint alias that uses regex and calling that alias with the timers, but to be honest, it's all Chinese to me. It's way too complicated for me to understand, as much as I've tried. cry

Joined: Jul 2006
Posts: 4,134
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,134
Join the channel in my signature, we can help you live in there.

For timer2 you can use $regsubex(%answer,/[^ ]/g,*) to replace every character in %answer (except for space codepoint 32) by an asterix, so your timer2 could be about sending just that.
For timer3, you can make a while loop on all the words and replace the non-first character & non-last character of the word by '*', or you can also just $regsubex(%answer,/\b[^ ]([^ ]+)[^ ]\b/g/,$str(*,$len(\1))) which should do the trick (untested but won't work for 2 letters word and less)
For timer4, you can start with the value from timer3 and just replace one '*' per word

You're not forced to use regex but they make the code way easier to read, I suggest you get helped on IRC where we can answer any question you have and help with non-regex, or regex solutions.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Jan 2012
Posts: 289
Fjord artisan
Offline
Fjord artisan
Joined: Jan 2012
Posts: 289
Try to testing this code:
Code
alias quest {
  var %file QA.txt | var %chan #channel | var %hintp1 2.5 | var %hintp2 1.5
  var %str $read(%file) | set %question $gettok(%str,1,124) | set %answer $gettok(%str,2,124)
  var %len $len(%answer) | var %words $numtok(%answer,32)
  var %par $+(05,$chr(40),03,%len 05letters,$chr(44)) $+(03,%words 05words,$chr(41))
  var %t | var %i 1 | while (%i <= %words) {
    var %s $gettok(%answer,%i,32) | var %w1 $floor($calc($len(%s) / %hintp1))
    var %w2 $mid(%s,1,%w1) | var %w3 $calc($len(%s) - %w1) | %t = %t $+(03,%w2,05,$str(*,%w3)) | inc %i
  } | var %hint1 %t
  var %t | var %i 1 | while (%i <= %words) {
    var %s $gettok(%answer,%i,32) | var %w1 $floor($calc($len(%s) / %hintp2))
    var %w2 $mid(%s,1,%w1) | var %w3 $calc($len(%s) - %w1) | %t = %t $+(03,%w2,05,$str(*,%w3)) | inc %i
  } | var %hint2 %t
  .timerQA1 1 0 msg %chan 05Question:03 %question %par
  .timerQA2 1 2 msg %chan 05Hint1:03 %hint1
  .timerQA3 1 4 msg %chan 05Hint2:03 %hint2
  .timerQA4 1 6 msg %chan 05Nobody answered the question. Correct answer: $+(03,%answer,05.)
}

Specify your channel in the %chan variable. To setting the display of the tooltip, use integers with a decimal separator in the variables %hintp1 and %hintp2.

To start, enter the command: "/quest".



🌐 http://forum.epicnet.ru πŸ“œ irc.epicnet.ru 6667 #Code | mIRC scripts, help, discuss, examples
Epic #269939 18/02/22 10:49 AM
Joined: Feb 2022
Posts: 12
P
Pikka bird
OP Offline
Pikka bird
P
Joined: Feb 2022
Posts: 12
It's not working as I want, bro. A) it's giving hints on the 1st hint, and I don't want that. Everything should be asterisked on the 1st hint. B) It's giving a lot of hints on the 2nd hint, sometimes even disclosing 3 letters on a 6 letter word answer. C) It's showing total letters and words as hint in the question, I don't want that. Perhaps I didn't explain well, so I will again, this time clearly:

To avoid confusion, let's stick with a four hint system, okay?

in QA file, there's this: Who founded Microsoft?|Bill Gates.

I want the bot to do these five steps:

Step 1: Post the question: Who founded Microsoft?

Step 2: Post 1st hint (all asterisked - no letter should be shown, with *exception I will explain below): Hint: **** *****

Step 3: Post 2nd hint (ONLY 1 letter from each word, the first. It MUST always be the first letter.): B*** G****

Step 4: Post 3rd hint (ONLY 1 more from each word, but random. Could be anywhere in the word, and it could be vowel or consonant. Doesn't matter.): B*l* G**e*

Step 5: Post 4th hint (ONLY 1 more from each word, but random. Could be anywhere in the word, but this time MUST be vowel if available, otherwise a consonant): Bil* Ga*e*


*Exception: Everything on the first hint should be asterisked. I want nothing to show except for punctuation marks that could be part of the answer. For example: commas, hyphens, dots and apostrophes. For example, a question could be Whose book was John talking about? and the answer could be Mary's As you can see, the ' in Mary's is part of the answer, so it should be shown. Name a famous cathedral? St. Paul's Here, both . and ' are part of the answer, so they should both be shown. In short: the first hint should ALL be asterisked except for punctuation marks.

One more quick example:

Q. What does the acronym USA stand for?

H1. ****** ****** ** *******
H2. U***** S***** O* A******
H3. U**t** S**t** Of A****c**
H4. U*it** S*at** Of A*e***c*

Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
Hey Pops, I see you came to channel looking for help, but you didn't stay very long. Not everyone is watching the channel 24x7. The channel topic asked you to ask your question into the channel then wait. But you did neither. frown
Your problem would probably take longer to solve, than the 14 minutes you remained in channel without asking your question.

Joined: Jul 2006
Posts: 4,134
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,134
Step 1: you're handling this one correctly
Step 2: $regsubex(%answer,/[^ [:punct:]]/ug,*)
Step 3: $regsubex(%answer,/(?:^|(?<= ))([^ [:punct:]])|([^ [:punct:]])()/Fgu,$iif(\2 != $null,*,\1))
Step 4: $regsubex(value from step 3,/([^ ]+)/g,$iif($pos(\1,*,$r(1,$pos(\1,*,0))),) $left(\1,$calc($v1 - 1)) $+ $mid(%answer,$calc($regml(\n).pos + $v1 - 1),1) $+ $mid(\1,$calc($v1 + 1)))
Step 5: $regsubex(value from step 4,/([^ ]+)/g,$iif($pos(\1,*,$r(1,$pos(\1,*,0))),) $left(\1,$calc($v1 - 1)) $+ $mid(%answer,$calc($regml(\n).pos + $v1 - 1),1) $+ $mid(\1,$calc($v1 + 1)))

[:punct:] equals [!"\#$%&'()*+,\-./:;<=>?@\[\\\]^_β€˜{|}~], all of these characters won't be replaced by *.


Example with %answer being Bill Gates :

Step 2: **** *****
Step 3: B*** G****
Step 4: (generated a few): Bi** G*t** - B**l Ga*** - Bi** G**e* - Bi** G**e* - Bi** G***s - B*l* G**e* - B*l* Ga*** - Bi** Ga***
Step 5: (generated a few using step4 = Bi** G*t**) Bi** Ga*** - Bi*l G*te* - Bi*l G*te* - Bil* G*te* - Bi*l G*t*s - Bi*l G*t*s - Bi*l Gat** - Bi*l G*te* - Bil* G*t*s - Bil* Gat** - Bil* Gat** - Bil* G*te* - Bi*l G*t*s - Bil* G*te* - Bi*l G*te* - Bil* Gat** - Bil* G*te* - Bi*l G*te*


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Wims #269950 19/02/22 02:37 PM
Joined: Feb 2022
Posts: 12
P
Pikka bird
OP Offline
Pikka bird
P
Joined: Feb 2022
Posts: 12
Unless you made a typo or missed out something, step 2 is not working.

Here's my code, using the one you gave me:

.timer1 1 10 msg %chan Hint: $regsubex(%answer,/[^ [!"\#$%&'()*+,\-./:;<=>?@\[\\\]^_β€˜{|}~]]/ug,*)

And it's returning this:

Hint: /[^ [!"\#$%&'()*+

I'm unable to trouble-shoot it because, like I said in the beginning of this thread, I've only learned basic scripting enough to create my own simple Trivia script. I know nothing about complicated identifiers like $regex or $regsubex.

Page 1 of 2 1 2

Link Copied to Clipboard