This repository has been archived on 2025-03-03. You can view files and clone it, but cannot push or open issues or pull requests.
nagios-scripts/ircbot.sh
2022-10-19 12:18:50 -07:00

65 lines
1.3 KiB
Bash
Executable File

#!/bin/sh
# TODO: make sure only nagios can write to $inputf and $msgf, else do not run
conf=/etc/ircbot.conf
if ! test -r $conf; then
echo "cannot read configuration file, exiting"
exit 1
else
. $conf
fi
touch $msgf
connect() {
echo "NICK $nick" > $inputf
echo "USER $nick 8 * : $nick" >> $inputf
echo "PRIVMSG NickServ : identify $password" >> $inputf
echo "JOIN $chan" >> $inputf
echo "PRIVMSG $chan : $joinmsg" >> $inputf
}
reconnect() {
exec $0
}
delay() {
while read line
do
sleep 1.5
echo $line
done
}
register() {
echo "PRIVMSG NickServ : register $password $email" >> $inputf
}
loop() {
tail -f $msgf | delay | while read line
do
echo "PRIVMSG #ops : $line" >> $inputf
done
}
connect
loop &
tail -f $inputf | delay | nc $server $port | while read msg
do
echo "$msg" | tee -a $logf
case "$msg" in
*'PING'*) echo "$msg" | sed 's/PING/PONG/' >> $inputf
;;
*'is not a registered nickname.'*) register
;;
*'You have not registered'*) register
;;
*'You have not joined'*) echo "JOIN $chan" >> $inputf
;;
*'Cannot join'*) sleep 10; echo "JOIN $chan" >> $inputf
;;
*'ERROR :Closing link:'*) reconnect
;;
esac
done