mata_bot

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

commit abd40d0d1f54a510a2dae21077f38ddb05d3a92c
parent ff52d78cdd15c4a3705b9e9bf42d0a469080c74a
Author: noodle <noodle@pastanoggin.com>
Date:   Sat, 14 Jun 2025 20:51:41 +0300

give mata_bot devil powers:

- absolute paths are now being used for the ball and quotes file
- default options changed to make local testing easier
- the makefile now installs to /usr/local: mata_bot.pl gets installed in sbin
as matabot, ball and quote go into share
- a PREFIX-aware rc script to run matabot as a daemon (configured during make)

makefile and rc script inspired by catgirl and kitd (thx June!)

Diffstat:
MMakefile | 31++++++++++++++++++++++++-------
Mmata_bot.pl | 36++++++++++++++++++++----------------
Arc_script.in | 14++++++++++++++
3 files changed, 58 insertions(+), 23 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,10 +1,27 @@ -PREFIX = /home/mata_bot +PREFIX = /usr/local +SHAREDIR = ${PREFIX}/share +RCDIR = /etc/rc.d -install: - install -g mata_bot -o mata_bot -d ${DISTDIR}${PREFIX}/bin - install -g mata_bot -m 0555 -o mata_bot mata_bot.pl ${DESTDIR}${PREFIX}/bin - install -g mata_bot -m 0444 -o mata_bot quotes ${DESTDIR}${PREFIX} - install -g mata_bot -m 0444 -o mata_bot ball ${DESTDIR}${PREFIX} +all: rc_script + +rc_script: rc_script.in + sed 's|%%PREFIX%%|${PREFIX}|g' rc_script.in >rc_script + +clean: + rm -f rc_script + +install: mata_bot.pl matabot.8 rc_script + install -d ${DISTDIR}${PREFIX}/sbin + install -d ${DISTDIR}${PREFIX}/share + 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 rc_script ${DESTDIR}${RCDIR}/matabot uninstall: - rm -f ${DESTDIR}${PREFIX}/bin/mata_bot.pl ${DESTDIR}${PREFIX}/ball + rm -f ${DESTDIR}${PREFIX}/sbin/matabot + rm -f ${DESTDIR}${SHAREDIR}/ball + rm -f ${DESTDIR}${SHAREDIR}/quotes + rm -f ${DESTDIR}${RCDIR}/matabot diff --git a/mata_bot.pl b/mata_bot.pl @@ -7,6 +7,7 @@ use IO::Socket qw(AF_INET SOCK_STREAM); use IO::Socket::SSL; use POSIX qw(strftime); +my $SHAREDIR = '/usr/local/share'; my $CHUNK_LENGTH = 1024; my $NICK = 'mata_bot'; my $USER = 'mata_bot_beta4'; @@ -17,21 +18,33 @@ my $MATA_HAPPY = '[^_^]'; my $MATA_DEAD = '[x~x]'; my $MATA_CUTE = '[>.<]'; -my $chan = '#unix_surrealism'; -my $host = 'irc.libera.chat'; +my $ball_path = "$SHAREDIR/matabot/ball"; +my $quotes_path = "$SHAREDIR/matabot/quotes"; +my $chan = '#testmatabot'; +my $host = 'localhost'; my $logging = 0; -my $port = '6697'; -my $tls = 1; +my $port = '6667'; +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'}); +$ball_path = $opts{'b'} if ($opts{'b'}); +$host = $opts{'h'} if ($opts{'h'}); +$chan = $opts{'j'} if ($opts{'j'}); +$port = $opts{'p'} if ($opts{'p'}); +$quotes_path = $opts{'q'} if ($opts{'q'}); + # read in the quotes file; -open (my $quotes_file, "<", "quotes") or die "couldn't open quotes: $!"; +open (my $quotes_file, "<", $quotes_path) or die "couldn't open quotes: $!"; 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") or die "couldn't open ball: $!"; +open (my $ball_file, "<", $ball_path) or die "couldn't open ball: $!"; chomp(my @ball = <$ball_file>); my $ball_num = $.; close $ball_file or die "$ball_file: $!"; @@ -45,8 +58,7 @@ sub randint { sub logger { my $logmessage = shift; - open(my $logfile, ">>", "bot.log") or die "Can't open bot.log: $!"; - print $logfile strftime('%Y-%m-%dT%H:%M:%SZ ', gmtime()), $logmessage, "\n"; + print strftime('%Y-%m-%dT%H:%M:%SZ ', gmtime()), $logmessage, "\n"; } sub out { @@ -181,14 +193,6 @@ sub respond { return 0; } -# process args -getopts('h:j:lp:t', \my %opts); -$chan = $opts{'j'} if ($opts{'j'}); -$host = $opts{'h'} if ($opts{'h'}); -$logging = 1 if ($opts{'l'}); -$port = $opts{'p'} if ($opts{'p'}); -$tls = 0 if ($opts{'t'}); - # start the connection my $sock; if ($tls) { diff --git a/rc_script.in b/rc_script.in @@ -0,0 +1,14 @@ +#!/bin/ksh + +daemon_logfile="/var/log/matabot.log" +daemon="%%PREFIX%%/sbin/matabot" +daemon_user="_matabot" + +. /etc/rc.d/rc.subr + +rc_bg=YES +rc_reload=NO + +pexp="/usr/bin/perl ${daemon}${daemon_flags:+ ${daemon_flags}}" + +rc_cmd $1