|
Joined: Feb 2011
Posts: 6
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
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
|
|
|
|
Joined: Feb 2004
Posts: 206
Fjord artisan
|
Fjord artisan
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!
|
|
|
|
Joined: Nov 2006
Posts: 1,559
Hoopy frood
|
Hoopy frood
Joined: Nov 2006
Posts: 1,559 |
Try if (!ding isin $strip($1)) { } (browse the /help for "isin" and "$strip")
|
|
|
|
Joined: Jul 2007
Posts: 1,129
Hoopy frood
|
Hoopy frood
Joined: Jul 2007
Posts: 1,129 |
Horstl, may you explain why the "isin" is preferred over "==" ?
|
|
|
|
Joined: Jul 2007
Posts: 1,129
Hoopy frood
|
Hoopy frood
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.
|
|
|
|
Joined: Oct 2004
Posts: 8,330
Hoopy frood
|
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
|
|
|
|
Joined: Feb 2011
Posts: 6
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
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.
|
|
|
|
Joined: Feb 2004
Posts: 206
Fjord artisan
|
Fjord artisan
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!
|
|
|
|
Joined: Jul 2007
Posts: 1,129
Hoopy frood
|
Hoopy frood
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?
|
|
|
|
Joined: Jul 2007
Posts: 1,129
Hoopy frood
|
Hoopy frood
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: on $*:text:/^!ding$/iS:*:{
|
|
|
|
Joined: Feb 2004
Posts: 206
Fjord artisan
|
Fjord artisan
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!
|
|
|
|
Joined: Jan 2007
Posts: 1,156
Hoopy frood
|
Hoopy frood
Joined: Jan 2007
Posts: 1,156 |
You can also use: on *:text:*:*:{
tokenize 32 $strip($1-)
if ($1 = !ding) { }
elseif ($1 = !dong) { }
}
|
|
|
|
Joined: Jul 2007
Posts: 1,129
Hoopy frood
|
Hoopy frood
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 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.
|
|
|
|
Joined: Jan 2007
Posts: 1,156
Hoopy frood
|
Hoopy frood
Joined: Jan 2007
Posts: 1,156 |
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. 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:*:*:{
}
|
|
|
|
Joined: Oct 2004
Posts: 8,330
Hoopy frood
|
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.
Invision Support #Invision on irc.irchighway.net
|
|
|
|
Joined: Jul 2007
Posts: 1,129
Hoopy frood
|
Hoopy frood
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.
|
|
|
|
Joined: Jan 2007
Posts: 1,156
Hoopy frood
|
Hoopy frood
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. }
|
|
|
|
Joined: Jul 2007
Posts: 1,129
Hoopy frood
|
Hoopy frood
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.
|
|
|
|
Joined: Sep 2005
Posts: 2,881
Hoopy frood
|
Hoopy frood
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: 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.
|
|
|
|
Joined: Oct 2004
Posts: 8,330
Hoopy frood
|
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
|
|
|
|
|