#!/usr/bin/env sh

initn="1"
maxn="3600"

olddate="$(date +%s)"
n="$initn"

while true; do
	ii/ii -i ~/offtopiabday -s irc.sortix.org -e ssl -p 6697 -n "happybot" -f 'Happy birthday! By which I mean existential crisis.'
	echo "[$(date)] Oh no, ii died."
	if [ "$(date +%s)" -lt "$(($olddate + $n + 60))" ]; then
		n="$((n * 7 / 2))"
		if [ "$n" -gt "$maxn" ]; then
			n="$maxn"
		fi
	else
		n="$initn"
	fi
	olddate="$(date +%s)"
	sleep "$n"
done