mIRC Homepage
Posted By: Gord10 Bot commands don't work with colored text - 19/02/11 12:32 AM
Hello everyone,

I am scripting a bot. This bot must be able to detect user lines like "!rules" in room and then execute the concerned mIRC command.


on *:text:*:*:{
if ( $1 == !ding) {
....

simply works when the command is in a standart form (i.e. not colorful or bold).

I tried to solve bold text and colorful text problem with
if ( $1 == !ding || $1 == !ding* || $1 == *!ding* )
but I still fail to detect colorful or bold texts (the odd characters represent the equilavent characters of bold or colorful texts).

Thanks in advance
if ($strip($1) = ...)

Cheers,

DK
Posted By: Horstl Re: Bot commands don't work with colored text - 19/02/11 01:16 AM
Try
Code:
if (!ding isin $strip($1)) { }
(browse the /help for "isin" and "$strip")
Posted By: Tomao Re: Bot commands don't work with colored text - 19/02/11 01:50 AM
Horstl, may you explain why the "isin" is preferred over "==" ?
Posted By: Tomao Re: Bot commands don't work with colored text - 19/02/11 02:02 AM
Another choice you can make for your bot is go to:

1. mIRC options
2. IRC
3. Expand it to Messages
4. Strip codes from incoming messages
5. check Color and Other box.

This way you don't need the $strip() identifier.
The only benefit of isin is if you want to match if someone adds punctuation or a something that might add variation to the word. For this situation, I'd think == would be better. Of course, isin could be used instead of $strip() and would work fairly well. I'd just use $strip() and == myself.
Posted By: Gord10 Re: Bot commands don't work with colored text - 19/02/11 03:01 AM
Thank you very much! What I needed was $strip.

About the isin discussion: Wouldn't it be perceived as positive when user typed "And you need to type !rules here" if isin is used? That wouldn't be so useful.
only if "$1-" is used instead of "$1". In the examples given above, only the first token (i.e. the first word) is tested, not the entire string.

Cheers,

DK
Posted By: Tomao Re: Bot commands don't work with colored text - 19/02/11 03:16 AM
If I understand you correctly, by using the operator isin, the $strip isn't needed in the first place?
Posted By: Tomao Re: Bot commands don't work with colored text - 19/02/11 03:18 AM
You can also use an on text regex with /S, which means to strip control codes...but it's kind of a waste though:
Code:
on $*:text:/^!ding$/iS:*:{
Tomao: Not a waste. This enables different ON TEXT events to be used for different strings. Benefits: better modularisation and no need for lengthy "if elseif then" statements. (main point: easier to maintain code).

Cheers,
DK
Posted By: DJ_Sol Re: Bot commands don't work with colored text - 19/02/11 04:47 AM
You can also use:

Code:
on *:text:*:*:{
tokenize 32 $strip($1-)

if ($1 = !ding) {  }
elseif ($1 = !dong) {  }

}
Posted By: Tomao Re: Bot commands don't work with colored text - 19/02/11 06:04 AM
Thanks for your input, Darwin. I always thought using one word for regex is a waste of its engine. I suppose it has its usefulness and benefit after all.

Using
Code:
on *:text:*:*:{
will have to make sure it's the only text event in the remote, along with never-ending if-then-else conditions. Many beginners tend to place multiple text events in the same remote, and the only one that works is the fist one on top.
Posted By: DJ_Sol Re: Bot commands don't work with colored text - 19/02/11 08:14 PM
Originally Posted By: Tomao

Using on *:text:*:*:{ will have to make sure it's the only text event in the remote, along with never-ending if-then-else conditions.


You can have other text events, but this one should be the last one.

Code:
on *:text:Hello:#:{ }
on *:text:Hello:?:{ }
on *:text:*:#:{
if ($1 = .hop) hop #
}
on *:text:*:?:{
if ($1 = .hop) msg $nick Silly rabbit tricks are for kids!
}
on *:text:*:*:{

}


Not entirely true. It depends on what the * matchtext needs to do. For example, if it's supposed to write a custom log file for every line seen, then it won't write that log file if someone says Hello. At least, not unless you're duplicating the code or using an alias or something in each on text event.

And, in your example, the * location will never trigger for channels or queries.

In general, you don't want more than one of the same event in a single script file unless you are paying careful attention to the order they are in. It's very easy to end up with conflicts if you're not careful. You can have more than one. Just watch what you're doing. smile
Posted By: Tomao Re: Bot commands don't work with colored text - 20/02/11 02:12 AM
:P I'm not really a big fan of having one text event with its own match text per routine and so on and so forth.
Posted By: DJ_Sol Re: Bot commands don't work with colored text - 20/02/11 02:28 AM
Of course, I never said the catchall events would trigger for the ones that triggered above. I used Hello as an example. Maybe to suit you I should have used a command or something. I'll change it so you don't nitpick my examples.

In general, you want to manage your text events correctly, but you can have as many as you need in the same file.

on *:text:!ding:#:{ }
on *:text:!ding:?:{ }
on *:text:*:#:{
;won't trigger if $1 = !ding
if ($1 = .hop) hop #
}
on *:text:*:?:{
;won't trigger if $1 = !ding
if ($1 = .hop) msg $nick Silly rabbit tricks are for kids!
}
on *:text:*:*:{
;won't trigger if $1 = !ding or .hop because those triggered above.
}
Posted By: Tomao Re: Bot commands don't work with colored text - 20/02/11 06:18 AM
With the diligent arrangement you've placed for each text event, it sort of looks disorderly and messy in a sense. I'm not implying that it's a substandard way of going about it, but it certainly increases the likelihood of unworkability if the conflict seeps through. Perhaps not for an experience MSL coder, but it'd be an easy prey for beginners.
Posted By: hixxy Re: Bot commands don't work with colored text - 20/02/11 01:04 PM
If you want to be really specific then you can use a regex event that will support loads of commands without matching everything (as is the case with *) like this:

Code:
alias commands return !ding !dong !ring !rong !ting !tong
alias commandregex {
  tokenize 32 $1
  var %i = 1, %result
  while ($($ $+ %i,2) != $null) {
    %result = %result $+(\Q,$replacecs($v1,\E,\E\\E\Q),\E)
    inc %i
  }
  return $+(/^,$chr(40),$replace(%result,$chr(32),$chr(124)),$chr(41),/iS)
}
on $*:text:$($commandregex($commands)):#:{
  echo -s $nick said $1- in # $+ !
  if ($regml(1) == !ding) { msg # dong! }
}


All of that \Q\E malarky is to escape any special characters that would make the regex fail. Characters like *, ?, |, +, etc have special meanings in regex.

Edit:

Riamus, in this case isin wouldn't work if there were control codes in the middle of the text you're trying to match.

if (xyz isin <b>abcxyz<b>) (where <b> is a bold control code) would work fine, but if (xyz isin abcx<b>yz<b>) would not.
@DJ_Sol: Yes, I know you know these things. I was trying to clarify for new scripters who would likely misunderstand. Your final on text still will not trigger in any channel or query, just in case you didn't notice that.
© mIRC Discussion Forums