Tobias Reisinger
d8cdc2bb11
All checks were successful
/ build-artifacts (push) Successful in 55s
Add event listener with JSON output (WIP) Add notifier on movement events Refactor Parameter and ParameterList (still shit)
105 lines
2.3 KiB
Bash
Executable file
105 lines
2.3 KiB
Bash
Executable file
#!/usr/bin/env sh
|
|
|
|
actions="quick
|
|
move
|
|
fetch-client
|
|
fetch-channel
|
|
away
|
|
not away
|
|
back
|
|
message
|
|
message-user
|
|
events-move"
|
|
|
|
_ts_control_get_entity() {
|
|
entity=$(_ts_control_single_or_dmenu "$(teamspeak-query-lib "$1s")" "$2")
|
|
if [ -z "$entity" ]; then
|
|
exit 1
|
|
fi
|
|
echo "$entity"
|
|
}
|
|
|
|
_ts_control_get_message() {
|
|
if [ -n "$1" ];
|
|
then
|
|
message="$1"
|
|
else
|
|
message=$(printf "\n" | $DMENU -p "message")
|
|
fi
|
|
|
|
if [ -z "$message" ]; then
|
|
exit 1
|
|
fi
|
|
|
|
echo "$message"
|
|
}
|
|
|
|
_ts_control_move_self() {
|
|
channel=$(_ts_control_get_entity channel "$1" "$2")
|
|
teamspeak-query-lib move --strict-channel "$channel"
|
|
}
|
|
|
|
_ts_control_fetch() {
|
|
target=$(_ts_control_get_entity "$1" "$2")
|
|
teamspeak-query-lib fetch "--strict-$1" "--$1" "$target"
|
|
}
|
|
|
|
_ts_control_single_or_dmenu() {
|
|
options=$(echo "$1" | grep "$2")
|
|
count=$(echo "$options" | wc -l)
|
|
if [ "$count" -eq 1 ]; then
|
|
echo "$options"
|
|
else
|
|
echo "$options" | $DMENU
|
|
fi
|
|
}
|
|
|
|
# Add '$' to $1 to add 'End of line' to the regex for grep
|
|
action=$(_ts_control_single_or_dmenu "$actions" "$1$")
|
|
|
|
case $action in
|
|
"quick")
|
|
action=$($DMENU < "$XDG_CONFIG_HOME/ts-control-quick")
|
|
if [ -z "$action" ]; then
|
|
exit 1
|
|
fi
|
|
eval "$0 $action"
|
|
;;
|
|
"move")
|
|
_ts_control_move_self "$2"
|
|
;;
|
|
"fetch-client")
|
|
_ts_control_fetch client "$2"
|
|
;;
|
|
"fetch-channel")
|
|
_ts_control_fetch channel "$2"
|
|
;;
|
|
"not away")
|
|
teamspeak-query-lib move "Not Away From Keyboard"
|
|
teamspeak-query-lib update --microphone=false --speakers=false
|
|
;;
|
|
"away")
|
|
message=$(_ts_control_get_message)
|
|
teamspeak-query-lib move "Away From Keyboard"
|
|
teamspeak-query-lib update --away "$message"
|
|
teamspeak-query-lib update --microphone=false --speakers=false --away "$message"
|
|
;;
|
|
"back")
|
|
teamspeak-query-lib update --back
|
|
_ts_control_move_self "$2"
|
|
teamspeak-query-lib update --microphone=true --speakers=true
|
|
;;
|
|
"message")
|
|
message=$(_ts_control_get_message "$2")
|
|
teamspeak-query-lib message "$message"
|
|
;;
|
|
"message-user")
|
|
user=$(_ts_control_get_entity client "$2")
|
|
message=$(_ts_control_get_message "$3")
|
|
teamspeak-query-lib message --strict-client --client "$user" "$message"
|
|
;;
|
|
"events-move")
|
|
teamspeak-query-lib events NotifyClientMoved NotifyClientEnterView \
|
|
| jq -r --unbuffered '.client.client_nickname + " joined " + .channel.channel_name // "the server"' \
|
|
| xargs -I{} notify-send "TS3 movement" "{}"
|
|
esac
|