mIRC Home    About    Download    Register    News    Help

Print Thread
Bot commands don't work with colored text #229877 19/02/11 12:32 AM
Joined: Feb 2011
Posts: 6
G
Gord10 Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
G
Joined: Feb 2011
Posts: 6
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

Re: Bot commands don't work with colored text [Re: Gord10] #229878 19/02/11 01:16 AM
Joined: Feb 2004
Posts: 206
D
Darwin_Koala Offline
Fjord artisan
Offline
Fjord artisan
D
Joined: Feb 2004
Posts: 206
if ($strip($1) = ...)

Cheers,

DK


Darwin_Koala

Junior Brat, In-no-cent(r)(tm) and original source of DK-itis!
Re: Bot commands don't work with colored text [Re: Gord10] #229879 19/02/11 01:16 AM
Joined: Nov 2006
Posts: 1,559
H
Horstl Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Try
Code:
if (!ding isin $strip($1)) { }
(browse the /help for "isin" and "$strip")

Re: Bot commands don't work with colored text [Re: Horstl] #229880 19/02/11 01:50 AM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Horstl, may you explain why the "isin" is preferred over "==" ?

Re: Bot commands don't work with colored text [Re: Gord10] #229881 19/02/11 02:02 AM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
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.

Re: Bot commands don't work with colored text [Re: Tomao] #229882 19/02/11 02:30 AM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
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.


Invision Support
#Invision on irc.irchighway.net
Re: Bot commands don't work with colored text [Re: Riamus2] #229883 19/02/11 03:01 AM
Joined: Feb 2011
Posts: 6
G
Gord10 Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
G
Joined: Feb 2011
Posts: 6
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.

Re: Bot commands don't work with colored text [Re: Gord10] #229884 19/02/11 03:07 AM
Joined: Feb 2004
Posts: 206
D
Darwin_Koala Offline
Fjord artisan
Offline
Fjord artisan
D
Joined: Feb 2004
Posts: 206
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


Darwin_Koala

Junior Brat, In-no-cent(r)(tm) and original source of DK-itis!
Re: Bot commands don't work with colored text [Re: Riamus2] #229885 19/02/11 03:16 AM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
If I understand you correctly, by using the operator isin, the $strip isn't needed in the first place?

Re: Bot commands don't work with colored text [Re: Gord10] #229886 19/02/11 03:18 AM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
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:*:{

Re: Bot commands don't work with colored text [Re: Tomao] #229887 19/02/11 03:49 AM
Joined: Feb 2004
Posts: 206
D
Darwin_Koala Offline
Fjord artisan
Offline
Fjord artisan
D
Joined: Feb 2004
Posts: 206
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


Darwin_Koala

Junior Brat, In-no-cent(r)(tm) and original source of DK-itis!
Re: Bot commands don't work with colored text [Re: Gord10] #229888 19/02/11 04:47 AM
Joined: Jan 2007
Posts: 1,156
D
DJ_Sol Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
You can also use:

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

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

}

Re: Bot commands don't work with colored text [Re: Darwin_Koala] #229891 19/02/11 06:04 AM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
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.

Re: Bot commands don't work with colored text [Re: Tomao] #229902 19/02/11 08:14 PM
Joined: Jan 2007
Posts: 1,156
D
DJ_Sol Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
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:*:*:{

}



Re: Bot commands don't work with colored text [Re: DJ_Sol] #229907 19/02/11 09:28 PM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
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


Invision Support
#Invision on irc.irchighway.net
Re: Bot commands don't work with colored text [Re: Riamus2] #229920 20/02/11 02:12 AM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
: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.

Re: Bot commands don't work with colored text [Re: Riamus2] #229921 20/02/11 02:28 AM
Joined: Jan 2007
Posts: 1,156
D
DJ_Sol Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
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.
}

Re: Bot commands don't work with colored text [Re: DJ_Sol] #229927 20/02/11 06:18 AM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
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.

Re: Bot commands don't work with colored text [Re: DJ_Sol] #229929 20/02/11 01:04 PM
Joined: Sep 2005
Posts: 2,881
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
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.

Last edited by hixxy; 20/02/11 01:09 PM.
Re: Bot commands don't work with colored text [Re: DJ_Sol] #229936 20/02/11 02:40 PM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
@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.


Invision Support
#Invision on irc.irchighway.net