This is a basic talker bot using the $regex alias for those who want to get started in Regular Expressions. There are a few triggers (These aren't case sensetive, punctuation won't affect it, and you can sort of mix it with other words):
Hey/Hi/Hello -
My name is -
(I'm or I am) years old -
lol (occassional trigger, 5-9 chance of triggering) -
I know this description may be kind of confusing, but just put this code in your bot, log onto another nickname, and type some of the above into the channel, you'll figure it out.
on *:TEXT:*:#:{
if ($regex($1-,(H|h)ello.|(H|h)ey.|(H|h)i. (.+?)\b) > 0) && ($regml(2) == $me) { msg $chan Hello, $+($nick,.) }
if ($regex($1-,(N|n)ame.is (.+)) > 0) { msg $chan Hello, $+($regml(2),.) I'm $+($me,$chr(44)) it's nice to meet you. ;) }
if ($regex($1-,(L|l)(O|o)(L|l)) > 0) {
if ($rand(0,9) < 4) { msg $chan LOL! Pretty funny stuff, $+($nick,!) }
elseif ($rand(0,9) < 4) { msg $chan It really wasn't that funny, $+($nick,.) }
}
if ($regex($1-,^((I|i).m|(I|i).am) (.+) (Y|y)ears.(O|o)ld) > 0) {
if ($regml(3) < 13) { msg $chan You're kidding, $+($nick,.) Only $v1 years old? | halt }
if ($regml(3) >= 100) { msg $chan Yeah, right. If you don't want to tell me your age $+([,$nick,]), just tell me. You don't have to lie about it! Pff, $regml(3) years old, right. | halt }
msg $chan Cool, $+($nick,.) I, for some reason, wish I was $+($regml(3),!)
}
}
The ?: I never knew about. I have never come across that any tutorials or from messing around with it, As I said to Yoinx \"Yoinx, I guess I just learned something new ;p.\" As for the digit, I know 1 and 0 represent a \"true/false\" value in a way, but it\'s a habit of mine that, as if someone didn\'t know I have OCD, bothers me if I don\'t follow through with it ;/ I\'ll try to quit, lol. Anyways, thanks for this tips FiberOptics ;p
Btw, on another note:
$regex always returns a digit in range 0-, in other words, you don\'t need to check for > 0.
In an if statement, when checking a value like: if (value)
the condition evaluates to $true when the value is not 0, not $false, and not $null. In the same way, the if statement returns $false, if the value was either 0, $false, or $null.
Since $regex is always a digit, we can already rule out the $true and $false, leaving us with only the digit 0 to make the if condition false.
Therefore \"if ($regex([name],value,))\" is sufficient.
You should always put your expressions between slashes / /
before you run into this situation:
//echo -a $regex(a,moo)
and wonder why it says there is 1 match...
Also, when you create regexes that capture a pattern, it\'s also a good idea to name your regexes, because everytime a regex captures, it overwrites the old results in $regml.
In cases where you are not planning to reference the captured results later with $regml, it is more efficient to create an uncapturing expression:
(?:L|l) instead of (L|l)
but anyway you should just use the i modifier which will make your expressoin case insensitive:
From: if ($regex($1-,(L|l)(O|o)(L|l)) > 0) {
to
if ($regex($1-,/lol/i)) {
The i modifier tells the regex engine that the specified alpha chars are case insensitive.
I could go on and on and give tips for improvement, but that would end up being a tutorial, something that already exists.