summaryrefslogblamecommitdiffstats
path: root/skripti/irc_antispam.sh
blob: 4e7a5132538e80086d007eacdbe7566f74174de5 (plain) (tree)











































                                                                                                                                      
#!/bin/bash
set -uexo pipefail
p=`rev <<<$0 | cut -d/ -f1 | rev`
umask 0007
d=`mktemp -p "" -d $p.XXX`
trap "rm -r $d" EXIT
mkfifo $d/s
mkfifo $d/c
tail -f $d/s | nc $1 6667 > $d/c &
u=dont_send_me_msg_
echo "USER $u `hostname` $1 :IRC Antispam bot. Do not PM, you will get G-Lined." > $d/s
echo "NICK antispam" > $d/s
echo "OPER $OPER" > $d/s
c="antispam_chan_dont_join_youll_get_gline_"
j="$c$RANDOM"
echo "JOIN #$j" > $d/s
while read l
do
	echo "$l"
	case `cut -d\  -f2 <<<"$l"` in
		433)
			echo "NICK bot$RANDOM" > $d/s
			echo "OPER $OPER" > $d/s
			echo "PART #$j" > $d/s
			j="$c$RANDOM"
			echo "JOIN #$j" > $d/s
			;;
		PRIVMSG|JOIN|PART)
			if grep -v $u <<<"$l"
			then
				i=`cut -d\  -f1 <<<"$l" | cut -d@ -f2`
				echo "GLINE *@$i 13376969 :You were G-Lined for spamming. Appeal via email to anton@sijanec.eu" > $d/s
			fi
			;;
	esac
	case `cut -d\  -f1 <<<"$l"` in
		PING)
			echo "PONG `cut -d\  -f2 <<<$l`" > $d/s
			echo "PART #$j" > $d/s
			j="$c$RANDOM"
			echo "JOIN #$j" > $d/s
			;;
	esac
done < $d/c