annna-channel-service - annna - Annna the nice friendly bot. HTML git clone git://bitreich.org/annna/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/annna/ DIR Log DIR Files DIR Refs DIR Tags DIR README --- annna-channel-service (1649B) --- 1 #!/bin/sh 2 # 3 # Per-channel daemon that monitors incoming messages from ii out script. 4 # 5 6 pgrep -f "$0 $*" | grep -vxq "$$" && exec echo "$0 $* already running" 7 #trap 'exec pkill -U annna -f "entr .* ${PWD}/out"' INT TERM EXIT HUP 8 9 server="$1" 10 channel="$2" 11 12 cfgbase="$(pwd)" 13 ircbase="$(cat ${cfgbase}/ircbase)" 14 ircuser="$(cat ${cfgbase}/${server}/ircuser)" 15 serverbase="${ircbase}/${server}" 16 modbase="$(cat ${cfgbase}/modbase)" 17 18 case "${channel}" in 19 \#bitreich-idle) 20 idlebase="${modbase}/idlerpg" 21 $idlebase/idlerpg-channel-service.py \ 22 "${ircuser}" "${idlebase}" "${ircbase}" "${server}" "${channel}" & 23 exit $? 24 ;; 25 \#bitreich-radio) 26 radiobase="${modbase}/radio" 27 $radiobase/radio-channel-service.sh \ 28 "${ircuser}" "${radiobase}" "${ircbase}" "${server}" "${channel}" & 29 esac 30 31 ls "${serverbase}/${channel}/out" \ 32 | entr tail -n 1 "${serverbase}/${channel}/out" 2>/dev/null \ 33 | { 34 while read -r line; 35 do 36 secondword="$(printf "%s\n" "${line}" | cut -d' ' -f 2)" 37 case "${secondword}" in 38 "-!-") 39 fifthword="$(printf "%s\n" "${line}" | cut -d' ' -f 5)" 40 cmd="" 41 # TODO: Add error, mode, nick, topic, kick, notice support. 42 case "${fifthword}" in 43 joined) cmd="JOIN";; 44 left) cmd="PART";; 45 quit) cmd="QUIT";; 46 esac 47 [ -z "$cmd" ] && break 48 user="$(printf "%s\n" "${line}" | cut -d' ' -f 3 | cut -d'(' -f 1)" 49 annna-channel-message "${server}" "${channel}" "${user}" "" "${cmd}" 50 ;; 51 "<"*">") 52 cmd="PRIVMSG" 53 printf "%s\n" "${line}" \ 54 | sed -nu 's,[0-9]* <\([^ >]*\)> \(.*\),\1 \2,p' \ 55 | { 56 while read -r user text; 57 do 58 annna-channel-message "${server}" "${channel}" "${user}" "${text}" "${cmd}" 59 done 60 } 61 ;; 62 esac 63 done 64 } 65