marvvin

[archived] IRC bot
git clone https://hhvn.uk/marvvin
git clone git://hhvn.uk/marvvin
Log | Files | Refs | README | LICENSE

main.sh (865B)


      1 #!/bin/sh
      2 
      3 nick=marvvin
      4 #comment=
      5 
      6 server=irc.hlirc.net
      7 port=6667
      8 input=input.fifo
      9 inlog=in.log
     10 outlog=out.log
     11 
     12 ####
     13 
     14 trap "kill -1 $$" 2
     15 trap "kill -1 $$" 15
     16 cd $(dirname $0)
     17 
     18 export nick server port input inlog outlog comment tmpdir
     19 
     20 # connect(host, port)
     21 [ "$tls" = "y" ] && {
     22 	connect(){
     23 		openssl s_client -connect "$1:$2"
     24 	}
     25 } || {
     26 	connect(){
     27 		nc "$1" "$2"
     28 	}
     29 }
     30 
     31 rm "$input"
     32 mkfifo "$input"
     33 (
     34 	printf '%s\r\n' "NICK $nick"
     35 	printf '%s\r\n' "USER $nick * * :${comment:-$nick}"
     36 ) | cat - $input        | \
     37 tee $outlog             | \
     38 connect $server $port   | \
     39 tee $inlog /dev/stderr  | \
     40 while read -r line
     41 do
     42 	export LINE="$(printf '%s\n' "$line" | sed 's/:[^ ]* //')"
     43 	export FROM="$(printf '%s\n' "$line" | grep -o '^:[^ ]*')"
     44 	export NICK="$(printf '%s\n' "$FROM" | sed -E 's/[:!]*([^:!]*).*/\1/')"
     45 	timeout 20 ./handler.rc
     46 done >/dev/null | tee $input