mata_bot

some cheeky bot for #unix_surrealism
git clone https://git.pastanoggin.com/mata_bot.git
Log | Files | Refs | README | LICENSE

commit 2a1492c1de32786cb1ed38ad5e194578d56bda44
parent 509cddf0ac6b76eacaefe3a31c7006a337443a20
Author: boredpasta <boredpasta@tutanota.com>
Date:   Fri, 21 Mar 2025 01:22:54 +0200

only accept dice command when prefixed by nick and improve other nick cmds

Diffstat:
Mmata_bot.pl | 29++++++++++++++---------------
1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/mata_bot.pl b/mata_bot.pl @@ -62,7 +62,17 @@ sub msg { sub respond_command { my ($sock, $sender_nick, $content) = @_; - if ($content =~ /\b{wb}good\b{wb}[^\000\r\n]*\b{wb}(bot|boy|girl)/) { + if ($content =~ /\b{wb}([1-9]\d*)?d([1-9]\d*)\b{wb}/) { + # we got dice + my $ndice = $1 // 1; + my $nface = $2; + my $min = $ndice; + my $max = $ndice * $nface; + my $result = $min + int rand(1 + $max - $min); + 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)/) { # we got a compliment if ($sender_nick eq $MOTHER) { msg($sock, "Thank you, mother! ${MATA_HAPPY}"); @@ -71,15 +81,13 @@ sub respond_command { } } elsif ($content =~ /\?$/) { # we got a question - unless ($sender_nick eq $MOTHER) { - msg($sock, "$ball[int rand($ball_num)] ${MATA_CUTE}"); - } + msg($sock, "$ball[int rand($ball_num)] ${MATA_CUTE}"); } else { # we got anything else if ($sender_nick eq $MOTHER) { msg($sock, "Done, mother! ${MATA_HAPPY}"); } else { - msg($sock, "$quotes[int rand($quotes_num)] ${MATA_NORM}"); + msg($sock, "\1ACTION leans over and places it's hand near it's antenna. \"HUUH?\" ${MATA_NORM}\1"); } } } @@ -97,16 +105,7 @@ sub respond_mention { # returns 1 if bot shouldn't remember last message for s///, 0 otherwise sub respond { my ($sock, $sender_nick, $message) = @_; - if ($message =~ /\b{wb}([1-9]\d*)?d([1-9]\d*)\b{wb}/) { - my $ndice = $1 // 1; - my $nface = $2; - my $min = $ndice; - my $max = $ndice * $nface; - my $result = $min + int rand(1 + $max - $min); - my $roll = "d${nface}"; - $roll = $ndice . $roll if $ndice > 1; - msg($sock, "${sender_nick} rolled a ${roll} and got ${result}! ${MATA_HAPPY}"); - } elsif ($subbuffer{$sender_nick} && $message =~ m,\b{wb}s/([^\000\r\n/]*)/([^\000\r\n/]*)/?,) { + if ($subbuffer{$sender_nick} && $message =~ m,\b{wb}s/([^\000\r\n/]*)/([^\000\r\n/]*)/?,) { # chat s/// my $toreplace = $1; my $replacement = $2;