Advertisement
Guest User

Untitled

a guest
May 22nd, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # Created by Malobre
  4. #
  5.  
  6. ts_instance="1"
  7. ts_serverQueryUser="serverQuery-user"
  8. ts_serverQueryPass="serverQuery-password"
  9. ts_host="127.0.0.1"
  10. ts_port="10011"
  11. ts_afkCid="3"
  12. ts_idleTimeBeforeMove="30"
  13.  
  14. exec 3>&1
  15.  
  16. if [[ ! -p pipe ]]; then
  17. mkfifo pipe
  18. fi
  19.  
  20. {
  21. echo "use $ts_instance"
  22. echo "login $ts_serverQueryUser $ts_serverQueryPass"
  23. echo "clientupdate client_nickname=AFK\sbot"
  24. while true; do
  25. echo "clientlist -voice"
  26. sleep 0.1
  27. while read -r line; do
  28. if [[ "${line}" == *clid* ]]; then break; fi
  29. done
  30. while read -r client; do
  31. if [[ ! $client =~ clid=([0-9]+).*cid=([0-9]+).*client_nickname=([A-z\\s]+).*client_output_muted=([01]) ]]; then continue; fi
  32. clid=${BASH_REMATCH[1]}
  33. cid=${BASH_REMATCH[2]}
  34. client_nickname="$(sed "s/\\\s/ /g" <<< "${BASH_REMATCH[3]}")"
  35. client_output_muted=${BASH_REMATCH[4]}
  36. if [[ $client_output_muted -eq 1 ]]; then
  37. if [[ $cid -ne $ts_afkCid ]]; then
  38. if [[ ! ${clientsIdleTime[${clid}]+foobar} ]]; then
  39. clientsIdleTime[${clid}]=$(date +%s);
  40. fi
  41. if [[ $(($(date +%s) - clientsIdleTime[clid])) -gt $ts_idleTimeBeforeMove ]]; then
  42. clientsLastChannel[${clid}]=$cid
  43. echo "Moving ${client_nickname} to the afk channel after ${ts_idleTimeBeforeMove} seconds of inactivity." >&3
  44. echo "clientmove clid=${clid} cid=${ts_afkCid}"
  45. fi
  46. fi
  47. else
  48. unset "clientsIdleTime[${clid}]"
  49. if [[ ${clientsLastChannel[${clid}]+foobar} ]] && [[ ${clientsLastChannel[${clid}]} -ne $ts_afkCid ]] && [[ ${clientsLastChannel[${clid}]} -ne $cid ]]; then
  50. echo "${client_nickname} is not AFK anymore, moving back." >&3
  51. echo "clientmove clid=${clid} cid=${clientsLastChannel[${clid}]}"
  52. fi
  53. fi
  54. done < <(echo "${line}" | tr -d "\r" | tr "|" "\n")
  55. done < pipe
  56. } | nc $ts_host $ts_port > pipe
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement