commit 2181aa718261264da0f6ad021ac22cb023c25cf0
parent a115fcfb9db5eabb3e049f7df02ae13dfd247713
Author: noodle <noodle@pastanoggin.com>
Date: Sun, 15 Jun 2025 02:24:43 +0300
make mata_bot smarter:
- added more language capabilites to the bot; like greetings, small
talk, and other responses to questions it gets typcially asked so it can
be more lively (added a new `hellos' file for choosing a random
greeting)
- added the *pray* command for prahou
- made link fetch error messages less noisy
- added case-insensitive flags to html regexes so we can accept
non-lowercase html
- links can now end anywhere before whitespace of end of line
Diffstat:
M | Makefile | | | 4 | +++- |
A | hellos | | | 14 | ++++++++++++++ |
M | mata_bot.pl | | | 81 | +++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------- |
M | matabot.8 | | | 24 | +++++++++++++++++------- |
4 files changed, 88 insertions(+), 35 deletions(-)
diff --git a/Makefile b/Makefile
@@ -18,8 +18,9 @@ install: mata_bot.pl matabot.8 rc_script
install -d ${DISTDIR}${SHAREDIR}/matabot
install -d ${DISTDIR}${RCDIR}
install mata_bot.pl ${DESTDIR}${PREFIX}/sbin/matabot
- install quotes ${DESTDIR}${SHAREDIR}/matabot/quotes
install ball ${DESTDIR}${SHAREDIR}/matabot/ball
+ install hellos ${DESTDIR}${SHAREDIR}/matabot/hellos
+ install quotes ${DESTDIR}${SHAREDIR}/matabot/quotes
install -m 644 matabot.8 ${DESTDIR}${MANDIR}/man8/matabot.8
install rc_script ${DESTDIR}${RCDIR}/matabot
@@ -27,5 +28,6 @@ uninstall:
rm -f ${DESTDIR}${PREFIX}/sbin/matabot
rm -f ${DESTDIR}${MANDIR}/man8/matabot.8
rm -f ${DESTDIR}${SHAREDIR}/ball
+ rm -f ${DESTDIR}${SHAREDIR}/hellos
rm -f ${DESTDIR}${SHAREDIR}/quotes
rm -f ${DESTDIR}${RCDIR}/matabot
diff --git a/hellos b/hellos
@@ -0,0 +1,14 @@
+Hallo
+Hello
+Hi
+Hai
+Hoi
+Oi
+Al-Salaamu Alaikum
+Greetings
+Hail
+Well met
+Salutations
+Mornings
+Noonafters
+Evenings
diff --git a/mata_bot.pl b/mata_bot.pl
@@ -15,11 +15,14 @@ my $REAL = 'death to technomage!!';
my $MOTHER = 'noodle';
my $MATA_NORM = '[._.]';
my $MATA_HAPPY = '[^_^]';
+my $MATA_SING = '[^=^]';
my $MATA_DEAD = '[x~x]';
my $MATA_CUTE = '[>.<]';
+my $MATA_FLIPOFF = 't[-_-t]';
my $ball_path = "$SHAREDIR/matabot/ball";
my $quotes_path = "$SHAREDIR/matabot/quotes";
+my $hellos_path = "$SHAREDIR/matabot/hellos";
my $chan = '#testmatabot';
my $host = 'localhost';
my $logging = 0;
@@ -28,27 +31,34 @@ my $tls = 0;
my %subbuffer;
# process args
-getopts('tlb:h:j:p:q:', \my %opts);
-$tls = 1 if ($opts{'t'});
-$logging = 1 if ($opts{'l'});
+getopts('tlH:b:h:j:p:q:', \my %opts);
$ball_path = $opts{'b'} if ($opts{'b'});
-$host = $opts{'h'} if ($opts{'h'});
$chan = $opts{'j'} if ($opts{'j'});
+$hellos_path = $opts{'H'} if ($opts{'H'});
+$host = $opts{'h'} if ($opts{'h'});
+$logging = 1 if ($opts{'l'});
$port = $opts{'p'} if ($opts{'p'});
$quotes_path = $opts{'q'} if ($opts{'q'});
+$tls = 1 if ($opts{'t'});
# read in the quotes file;
-open (my $quotes_file, "<", $quotes_path) or die "couldn't open quotes: $!";
+open (my $quotes_file, "<", $quotes_path) or die "couldn't open ${quotes_path}: $!";
chomp(my @quotes = <$quotes_file>);
my $quotes_num = $.;
close $quotes_file or die "$quotes_file: $!";
# read in the 8ball file
-open (my $ball_file, "<", $ball_path) or die "couldn't open ball: $!";
+open (my $ball_file, "<", $ball_path) or die "couldn't open ${ball_path}: $!";
chomp(my @ball = <$ball_file>);
my $ball_num = $.;
close $ball_file or die "$ball_file: $!";
+# read in the hellos file
+open (my $hellos_file, "<", $hellos_path) or die "couldn't open ${hellos_path}: $!";
+chomp(my @hellos = <$hellos_file>);
+my $hellos_num = $.;
+close $hellos_file or die "$hellos_file: $!";
+
sub randint {
my($min, $max) = @_;
return $min if $min == $max;
@@ -84,30 +94,47 @@ sub respond_command {
my $roll = "d${nface}";
$roll = $ndice . $roll if $ndice > 1;
msg($sock, "${sender_nick} rolled a ${roll} and got ${result}! ${MATA_HAPPY}");
- } elsif ($content =~ /\b{wb}good\b{wb}[^\000\r\n]*\b{wb}(bot|boy|girl)/) {
+ } elsif ($content =~ /^(g('day|ood +(day|morning|evening))|h(([aeo](i|llo)|ey|i(ya)?)( +there)?|owdy)|oi|yo|(al-)?salaa?mu( +alaikum)|greetings|hail|well met|salutations|(morn|even)ings|noonafters)\W*$/i) {
+ msg($sock, "$hellos[int rand($hellos_num)], ${sender_nick}! ${MATA_HAPPY}");
+ } elsif ($content =~ /pray/) {
+ msg($sock, "Stay prayed up!! ${MATA_CUTE}");
+ } elsif ($content =~ /^(what('| i)s +(up|happening|cracking)|(was)?sup)\W*$/i) {
+ msg($sock, "Looking for technomage, and you? ${MATA_NORM}");
+ } elsif ($content =~ /^who('| +i)s +a +good +boy\W*$/i) {
+ msg($sock, "Me! ${MATA_CUTE}");
+ } elsif ($content =~ /\?$/) {
+ # we got a question
+ msg($sock, "$ball[int rand($ball_num)] ${MATA_CUTE}");
+ } elsif ($content =~ /^good *(bo[tyi]|girl)\W*$/i) {
# we got a compliment
if ($sender_nick eq $MOTHER) {
msg($sock, "Thank you, mother! ${MATA_HAPPY}");
} else {
msg($sock, "Thanks! ${MATA_HAPPY}");
}
- } elsif ($content =~ /\?$/) {
- # we got a question
- msg($sock, "$ball[int rand($ball_num)] ${MATA_CUTE}");
+ } elsif ($content =~ /^bru[hv]\W*$/i) {
+ msg($sock, "Did i stutter? ${MATA_NORM}");
+ } elsif ($content =~ /^(h(ow)? *(are|r) *(yo)?u( +doing( +today)?)?|how('| i)s +(it +going|life|everything))\W*$/i) {
+ msg($sock, "I feel fantaaaastic... hey, hey, hey! ${MATA_SING}");
+ } elsif ($content =~ /^(thanks|thx|thank +(yo)?u)( +a *lot)?\W*$/i) {
+ msg($sock, "You're welcome, ${sender_nick}! ${MATA_HAPPY}");
+ } elsif ($content =~ /^i *l(ove)? *(you|y|u)\W*$/i) {
+ msg($sock, "<3");
+ } elsif ($content =~ /^f(u?ck)? +(yo)?u\W*$/i) {
+ msg($sock, "$MATA_FLIPOFF");
+ } elsif ($sender_nick eq $MOTHER) {
+ msg($sock, "Done, mother! ${MATA_HAPPY}");
} else {
- # we got anything else
- if ($sender_nick eq $MOTHER) {
- msg($sock, "Done, mother! ${MATA_HAPPY}");
- } else {
- msg($sock, "\1ACTION leans over and places it's hand near it's antenna. \"HUUH?\" ${MATA_NORM}\1");
- }
+ msg($sock, "\1ACTION leans over and places it's hand near it's antenna. \"HUUH?\" ${MATA_NORM}\1");
}
}
sub respond_mention {
- my ($sock, $sender_nick) = @_;
+ my ($sock, $sender_nick, $message) = @_;
if ($sender_nick eq $MOTHER) {
msg($sock, "Yes, mother? ${MATA_HAPPY}");
+ } elsif ($message =~ /^${NICK}\W*$/) {
+ msg($sock, "${MATA_NORM} ?");
} else {
msg($sock, "$quotes[int rand($quotes_num)] ${MATA_NORM}");
}
@@ -139,7 +166,7 @@ sub respond {
return 0;
}
my $content = $response->{content};
- if ($content =~ m,<span class="title"><a href="https://www\.youtube\.com/watch\?v=$video_id" accesskey="0">([^<]+)</a>,) {
+ if ($content =~ m,<span class="title"><a href="https://www\.youtube\.com/watch\?v=$video_id" accesskey="0">([^<]+)</a>,i) {
my $title = $1;
$title =~ tr/[\000\r\n]//d;
$title = trim($title);
@@ -147,16 +174,16 @@ sub respond {
} else {
msg($sock, "failed to get title of video ${video_id} ${MATA_DEAD} (no videos matching ID $video_id!)");
}
- } elsif ($message =~ m,(https?://[^\000\r\n ]+)$,) {
+ } elsif ($message =~ m,(https?://[^\000\r\n ]+),) {
my $url = $1;
# get in it's HEAD to check if it's text/html
my $response = HTTP::Tiny->new->head($url);
unless ($response->{success}) {
- msg($sock, "failed to get info about link: ${url} ${MATA_DEAD} ($response->{status} $response->{reason}!)");
+ msg($sock, "$response->{status} $response->{reason} (HEAD ${url}) ${MATA_DEAD} ");
return 0;
}
unless ($response->{headers}->{'content-type'}) {
- msg($sock, "failed to get info about link: ${url} ${MATA_DEAD} (no ``content-type'' header found in HTTP response!)");
+ msg($sock, "no content-type header in HTTP response (HEAD ${url}) ${MATA_DEAD}");
return 0;
}
unless ($response->{headers}->{'content-type'} =~ m,text/html,) {
@@ -168,27 +195,27 @@ sub respond {
# if it's text/html, GET it's title
$response = HTTP::Tiny->new->get($url);
unless ($response->{success}) {
- msg($sock, "failed to get title of link ${url} ${MATA_DEAD} ($response->{status} $response->{reason}!)");
+ msg($sock, "$response->{status} $response->{reason} (GET ${url}) ${MATA_DEAD}");
return 0;
}
unless (length $response->{content}) {
- msg($sock, "failed to get title of link ${url} ${MATA_DEAD} (HTTP response empty!)");
+ msg($sock, "Empty HTTP response (GET ${url}) ${MATA_DEAD}");
return 0;
}
my $content = $response->{content};
- if ($content =~ m,<title[^>]*>([^<]+)</title[^>]*>,) {
+ if ($content =~ m,<title[^>]*>([^<]+)</title[^>]*>,i) {
my $title = $1;
$title =~ tr/[\000\r\n]//d;
$title = trim($title);
msg($sock, "Title: $title");
} else {
- msg($sock, "failed to get title of link ${url} ${MATA_DEAD} (no title found!)");
+ msg($sock, "No title found (GET ${url} ${MATA_DEAD}");
}
} elsif ($message =~ /\b${NICK}\b/) {
- if ($message =~ /^ *${NICK}[:, ] *([^\000\r\n]+)$/) {
+ if ($message =~ /^ *${NICK}[:, ] *([^\000\r\n]+)$/ or $message =~ /^([^\000\r\n]+)[, ] *${NICK}\W*$/) {
respond_command($sock, $sender_nick, $1);
} else {
- respond_mention($sock, $sender_nick);
+ respond_mention($sock, $sender_nick, $message);
}
}
return 0;
diff --git a/matabot.8 b/matabot.8
@@ -53,24 +53,34 @@ load the quotes file from
.Po default: Pa $PREFIX/share/matabot/quotes Pc Ns .
.El
.Sh COMMANDS
-Bot can do some tricks:
+Bot can do some tricks (non-exhaustive list. he's kinda flexible so just speak to him :3):
.Bl -tag -width Ds
-.It *mata_bot*
+.It ...mata_bot...
Says something! This boy talks back!?
-.It mata_bot[:, ] What doth life? or mata_bot, What doth life?
+.It mata_bot, What doth life? or mata_bot, What doth life?
Answers your burning questions... (can't hear you if you don't
.Sq \&?
him).
-.It http://what.ever/idk#lol or https://what.ever/idk#lol
+.It ...http://what.ever/idk#lol... or ...https://what.ever/idk#lol...
Reads the website title or content-type for you.
-.It *watch?=SOMEID*
+.It ...watch?=SOMEID...
Reads out the youtube video title for you (make sure that the char after end of
.Sq SOMEID
is outside the range of valid characters for youtube video ID's okay?).
-.It mata_bot[:, ]*${number1}d${number2}*
+.It mata_bot ...${number1}d${number2}...
Rolls some ${number1} of ${number2}-sided dice. He's a dungeon master too!!
-.It mata_bot[:, ]*good*(bot|boy|girl)*
+.It mata_bot, good boy! (or boi, girl, bot)
+Praise your future master.
+.It thank you mata_bot!!
Thank your future master.
+.It hi, mata_bot!
+Say hi to the boy
+.It mata_bot: *pray*
+Stay prayed up!!
+.It wassup mata_bot?
+Ask him what he's up to.
+.It mata_bot, hru?
+ask him how he's doin.
.El
.Sh ENVIRONMENT
.Bl -tag -width Ds