mata_bot

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

commit 511bd5fb6f999ef2f9fd3dd38c8342c099f3afe0
parent 9182b34d48f64b05205ec771911c24bcdf4c460a
Author: boredpasta <boredpasta@tutanota.com>
Date:   Thu, 20 Mar 2025 18:44:40 +0200

refactor replies and make them smarter (now with analognowhere quotes!)

Diffstat:
Mmata_bot.pl | 83+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------
Aquotes | 20++++++++++++++++++++
2 files changed, 82 insertions(+), 21 deletions(-)

diff --git a/mata_bot.pl b/mata_bot.pl @@ -12,6 +12,10 @@ my $NICK = 'mata_bot'; my $USER = 'mata_bot_beta4'; my $REAL = 'death to technomage!!'; my $MOTHER = 'anelli'; +my $MATA_NORM = '[._.]'; +my $MATA_HAPPY = '[^_^]'; +my $MATA_DEAD = '[x~x]'; +my $MATA_CUTE = '[>.<]'; my $chan = '#unix_surrealism'; my $host = 'irc.libera.chat'; @@ -20,6 +24,19 @@ my $port = '6697'; my $tls = 1; my %subbuffer; +# read in the quotes file; +open (my $quotes_file, "<", "quotes") or die "couldn't open quotes: $!"; +chomp(my @quotes = <$quotes_file>); +my $quotes_num = $.; +close $quotes_file or die "$quotes_file: $!"; + +sub randint { + my($min, $max) = @_; + return $min if $min == $max; + ($min, $max) = ($max, $min) if $min > $max; + return $min + int rand(1 + $max - $min); +} + sub logger { my $logmessage = shift; open(my $logfile, ">>", "bot.log") or die "Can't open bot.log: $!"; @@ -37,11 +54,43 @@ sub msg { out($sock, "PRIVMSG $chan :$message"); } +sub respond_command { + my ($sock, $sender_nick, $content) = @_; + if ($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}"); + } else { + msg($sock, "Thanks! ${MATA_HAPPY}"); + } + } elsif ($content =~ /\?$/) { + # we got a question + unless ($sender_nick eq $MOTHER) { + msg($sock, "lol idk ${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}"); + } + } +} + +sub respond_mention { + my ($sock, $sender_nick) = @_; + if ($sender_nick eq $MOTHER) { + msg($sock, "Yes, mother? ${MATA_HAPPY}"); + } else { + msg($sock, "$quotes[int rand($quotes_num)] ${MATA_NORM}"); + } +} + # respond to channel # returns 1 if bot shouldn't remember last message for s///, 0 otherwise sub respond { my ($sock, $sender_nick, $message) = @_; - # if no triggers found, check for mentions if ($subbuffer{$sender_nick} && $message =~ m,\b{wb}s/([^\000\r\n/]*)/([^\000\r\n/]*)/?,) { # chat s/// my $toreplace = $1; @@ -55,11 +104,11 @@ sub respond { my $video_id = $1; my $response = HTTP::Tiny->new->get("https://fuyt.lab8.cz/?s=${video_id}&o=relevance"); unless ($response->{success}) { - msg($sock, "failed to get title of video $video_id <[x~x]> ($response->{status} $response->{reason}!)"); + msg($sock, "failed to get title of video ${video_id} ${MATA_DEAD} ($response->{status} $response->{reason}!)"); return 0; } unless (length $response->{content}) { - msg($sock, "failed to get title of youtube video $video_id <[x~x]> (HTTP response empty!)"); + msg($sock, "failed to get title of youtube video ${video_id} ${MATA_DEAD} (HTTP response empty!)"); return 0; } my $content = $response->{content}; @@ -69,18 +118,18 @@ sub respond { $title = trim($title); msg($sock, "YouTube: $title"); } else { - msg($sock, "failed to get title of video $video_id <[x~x]> (no videos matching ID $video_id!)"); + 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 ]+)$,) { 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 <[x~x]> ($response->{status} $response->{reason}!)"); + msg($sock, "failed to get info about link: ${url} ${MATA_DEAD} ($response->{status} $response->{reason}!)"); return 0; } unless ($response->{headers}->{'content-type'}) { - msg($sock, "failed to get info about link: $url <[x~x]> (no ``content-type'' header found in HTTP response!)"); + msg($sock, "failed to get info about link: ${url} ${MATA_DEAD} (no ``content-type'' header found in HTTP response!)"); return 0; } unless ($response->{headers}->{'content-type'} =~ m,text/html,) { @@ -92,11 +141,11 @@ 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 <[x~x]> ($response->{status} $response->{reason}!)"); + msg($sock, "failed to get title of link ${url} ${MATA_DEAD} ($response->{status} $response->{reason}!)"); return 0; } unless (length $response->{content}) { - msg($sock, "failed to get title of link $url <[x~x]> (HTTP response empty!)"); + msg($sock, "failed to get title of link ${url} ${MATA_DEAD} (HTTP response empty!)"); return 0; } my $content = $response->{content}; @@ -106,21 +155,13 @@ sub respond { $title = trim($title); msg($sock, "Title: $title"); } else { - msg($sock, "failed to get title of link $url <[x~x]> (no title found!)"); - } - } elsif ($message =~ /^${NICK}(:|,)? *[^\000\r\n\ ]+/) { - # we got a command - if ($sender_nick =~ /^${MOTHER}$/) { - msg($sock, "Done, mother! <[^_^]>"); - } else { - msg($sock, "${sender_nick}: BSOD!! <[x~x]>"); + msg($sock, "failed to get title of link ${url} ${MATA_DEAD} (no title found!)"); } - } elsif ($message =~ /${NICK}/) { - # we got mentioned - if ($sender_nick =~ /^${MOTHER}$/) { - msg($sock, "Yes, mother? <[^_^]>"); + } elsif ($message =~ /\b${NICK}\b/) { + if ($message =~ /^ *${NICK}[:, ] *([^\000\r\n]+)$/) { + respond_command($sock, $sender_nick, $1); } else { - msg($sock, "${sender_nick}: Bleep Bloop? <[._.]>"); + respond_mention($sock, $sender_nick); } } return 0; diff --git a/quotes b/quotes @@ -0,0 +1,20 @@ +Holy fscking flatpak! I can't feel my fscking face! What the fsck! Why does it hurt so much! No!! +Uhh... I guess you can use our phone app- +...would make our product a de-facto standard among reliable services. +Look at phase 3. +One hacker down. Approximately 14 minutes ago the bastard tried accessing matavids with an unsupported browser... +Meaning you get patched out if you disobey. +They despise your kind because you understand the machine, while they have to turn jungles into fuel and enslave thousands of computers just to pretend the machine speaks to them too. +Did you seriously bring a sowrd to a gunfight? +Fscking typical... +Maybe your question should not be: 'How do I master the machine?' Instead ask yourself: 'How do I earn its respect?' Anyway... coffee? +JavaScript. +floppy73.img +...and my maker took me outside to see the stars. I said: `It's beautiful... what does it mean?' She broke into tears: `It means you are condemned to being.' +Website? +You didn't _really_ think I would telnet into venus? +Godspeed, Pentium-M Man. +Um.. What's happening? +..I'm just gonna go.. +I can't beleive I'm out here hunting a rabbit. +Pretty sure I'm just a metaphor.