Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # Created by Malobre
- #
- ts_instance="1"
- ts_serverQueryUser="serverQuery-user"
- ts_serverQueryPass="serverQuery-password"
- ts_host="127.0.0.1"
- ts_port="10011"
- ts_afkCid="3"
- ts_idleTimeBeforeMove="30"
- exec 3>&1
- if [[ ! -p pipe ]]; then
- mkfifo pipe
- fi
- {
- echo "use $ts_instance"
- echo "login $ts_serverQueryUser $ts_serverQueryPass"
- echo "clientupdate client_nickname=AFK\sbot"
- while true; do
- echo "clientlist -voice"
- sleep 0.1
- while read -r line; do
- if [[ "${line}" == *clid* ]]; then break; fi
- done
- while read -r client; do
- if [[ ! $client =~ clid=([0-9]+).*cid=([0-9]+).*client_nickname=([A-z\\s]+).*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]}
- 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 the afk channel after ${ts_idleTimeBeforeMove} seconds of inactivity." >&3
- echo "clientmove clid=${clid} cid=${ts_afkCid}"
- fi
- fi
- else
- unset "clientsIdleTime[${clid}]"
- if [[ ${clientsLastChannel[${clid}]+foobar} ]] && [[ ${clientsLastChannel[${clid}]} -ne $ts_afkCid ]] && [[ ${clientsLastChannel[${clid}]} -ne $cid ]]; then
- echo "${client_nickname} is not AFK anymore, moving back." >&3
- echo "clientmove clid=${clid} cid=${clientsLastChannel[${clid}]}"
- fi
- fi
- done < <(echo "${line}" | tr -d "\r" | tr "|" "\n")
- done < pipe
- } | nc $ts_host $ts_port > pipe
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement