Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # Created by Malobre
- #
- ts_serverID="1"
- ts_serverQueryHost="127.0.0.1"
- ts_serverQueryPort="10011"
- ts_serverQueryUser="queryUser"
- ts_serverQueryPass="queryPass"
- ts_afkCid="1"
- ts_idleTimeBeforeMove="30"
- if [[ ! -p inpipe ]]; then
- mkfifo inpipe
- fi
- if [[ ! -p outpipe ]]; then
- mkfifo outpipe
- fi
- sleep 10000 > inpipe &
- sendCommand() {
- echo "${1}" > inpipe
- }
- while true; do
- nc $ts_serverQueryHost $ts_serverQueryPort < inpipe > outpipe &
- netcat_PID=$!
- sendCommand "use $ts_serverID"
- sendCommand "login $ts_serverQueryUser $ts_serverQueryPass"
- sendCommand "clientupdate client_nickname=AFK\sbot"
- while sleep 0.5; do
- sendCommand "clientlist -voice"
- done &
- while ps -p $netcat_PID > /dev/null; do
- response=""
- while read -r tmp; do
- if [[ "${tmp}" =~ error\ id=([0-9]+)\ msg=(.*) ]]; then
- errorId=${BASH_REMATCH[1]}
- errorMsg=${BASH_REMATCH[2]}
- if [[ errorId -ne 0 ]]; then
- echo "Error ${errorId}: $(sed "s/\\\s/ /g" <<< "${errorMsg}")"
- fi
- break
- fi
- response="${response} $(echo "${tmp}" | tr -d "\r")"
- done
- clientsConnected=()
- while read -r client; do
- if [[ ! $client =~ clid=([0-9]+).*cid=([0-9]+).*client_nickname=([^ ]+).*client_output_muted=([01]) ]]; then continue; fi
- clid=${BASH_REMATCH[1]}
- cid=${BASH_REMATCH[2]}
- client_nickname="$(sed "s/\\\s/ /g" <<< "${BASH_REMATCH[3]}")"
- client_output_muted=${BASH_REMATCH[4]}
- clientsConnected[${clid}]=${clid}
- if [[ $client_output_muted -eq 1 ]]; then
- if [[ $cid -ne $ts_afkCid ]]; then
- if [[ ! ${clientsIdleTime[${clid}]+foobar} ]]; then
- clientsIdleTime[${clid}]=$(date +%s);
- fi
- if [[ $(($(date +%s) - clientsIdleTime[clid])) -gt $ts_idleTimeBeforeMove ]]; then
- clientsLastChannel[${clid}]=$cid
- echo "Moving ${client_nickname} to channel ${ts_afkCid} after ${ts_idleTimeBeforeMove} seconds of inactivity."
- sendCommand "clientmove clid=${clid} cid=${ts_afkCid}"
- fi
- fi
- else
- if [[ ${clientsLastChannel[${clid}]+foobar} ]] && [[ ${clientsLastChannel[${clid}]} -ne $cid ]] && [[ ${clientsIdleTime[${clid}]+foobar} ]]; then
- echo "${client_nickname} is not AFK anymore, moving back."
- sendCommand "clientmove clid=${clid} cid=${clientsLastChannel[${clid}]}"
- unset "clientsLastChannel[${clid}]"
- unset "clientsIdleTime[${clid}]"
- fi
- fi
- done < <(echo "${response}" | tr "|" "\n")
- for clid in "${!clientsIdleTime[@]}"; do
- if [[ ! "${clientsConnected[@]}" =~ ${clid} ]]; then
- unset "clientsIdleTime[${clid}]"
- fi
- done
- done < outpipe
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement