matabot

a silly irc bot
git clone ssh://anon@git.pastanoggin.com
Log | Files | Refs | README | LICENSE

commit 8bd45e7d5623562961dfadff125f318921abb447
parent f3609fac601b54d2d303f2588e6ec35858bbaa00
Author: noodle <noodle@pastanoggin.com>
Date:   Thu, 25 Sep 2025 20:14:30 +0000

add a bible command and extra sanitization before sending anything out

Diffstat:
Mmata_bot.pl | 20+++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/mata_bot.pl b/mata_bot.pl @@ -8,7 +8,8 @@ use IO::Socket qw(AF_INET SOCK_STREAM); use IO::Socket::SSL; use POSIX qw(strftime); -my $CHUNK_LENGTH = 1024; +my $BIBLE_VERSES = 31102; +my $CHUNK_LENGTH = 512; my $CONNECT_TIMEOUT = 60; my $RECONNECT_TIME = 60; my $SOCK_TIMEOUT = 10; @@ -103,6 +104,15 @@ sub respond_command { yo+ )\b{wb}/ix) { $reply = "$hellos->[rand @$hellos], ${sender_nick}! ${MATA_HAPPY}" + } elsif ($content =~ /g[o-]d+/i) { + my $response = HTTP::Tiny->new->get("http://triapul.cz/files/bible/@{[randint(1, $BIBLE_VERSES)]}"); + $reply = "God is Dead!! ${MATA_CUTE}"; + if ($response->{success}) { + my $body = $response->{content}; + $body =~ tr/\000\r\n//d; + $body = trim($body); + $reply = $body if $body; + } } elsif ($sender_nick eq $MOTHER) { $reply = "Done, mother! ${MATA_HAPPY}" } else { @@ -165,7 +175,7 @@ sub respond { my $body = $response->{content}; if ($body =~ 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 =~ tr/\000\r\n//d; $title = trim($title); $reply = "YouTube: ${title}"; } else { @@ -202,7 +212,7 @@ sub respond { my $body = $response->{content}; if ($body =~ m,<title[^>]*>([^<]+)</title[^>]*>,i) { my $title = $1; - $title =~ tr/[\000\r\n]//d; + $title =~ tr/\000\r\n//d; $title = trim($title); $reply = "Title: ${title}"; } else { @@ -308,6 +318,10 @@ sub evasdrop { my $sender_nick = $1; my $sender_message = $2; ($subbuffer->{$sender_nick}, $reply) = respond($lists, $subbuffer, $sender_nick, $sender_message); + # sanitize text and and form msg + $reply =~ tr/\000\r\n//d; + $reply = trim($reply); + $reply = substr($reply, 0, $CHUNK_LENGTH-length("PRIVMSG #$opts->{'chan'} :")); $reply = "PRIVMSG $opts->{'chan'} :${reply}" if $reply; } out($sock, $opts, $reply) if $reply;