Add split command
All checks were successful
/ build-upload (push) Successful in 1m57s

This commit is contained in:
Tobias Reisinger 2025-07-27 12:30:17 +02:00
parent 6b7b549029
commit 6dddeb9c2e
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
8 changed files with 91 additions and 17 deletions

View file

@ -1,6 +1,7 @@
actions=(
"quick"
"move"
"split"
"fetch-client"
"fetch-channel"
"migrate"

View file

@ -1,6 +1,6 @@
name: ts-control
help: Teamspeak query lib utility script
version: 0.1.0
version: 0.2.0
environment_variables:
- name: ts3_client_api_key
@ -11,6 +11,7 @@ commands:
- name: ask
default: force
- name: quick
- name: split
- name: move
args:
- name: channel

View file

@ -1,4 +1,4 @@
action=$($DMENU < "$XDG_CONFIG_HOME/ts-control-quick")
action=$($DMENU < "$XDG_CONFIG_HOME/ts-control/quick")
if [ -z "$action" ]; then
exit 1
fi

View file

@ -0,0 +1,64 @@
ts_clients=$(teamspeak-query-lib clients --uid)
ts_online=$(grep ~/.config/ts-control/steam_map.txt -Ff <(echo "$ts_clients" | awk '{print $1}'))
friend_ids=$(echo "$ts_online" | awk '{print $1}' | paste -sd ',')
friends=$(curl -s "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=$STEAM_KEY&steamids=$friend_ids" \
| jq '.response.players[] | {steamid, gameid, gameextrainfo}')
steamid_to_tsname() {
local steamid="$1"
ts_uid=$(grep -F "$steamid" ~/.config/ts-control/steam_map.txt | awk '{print $2}')
echo "$ts_clients" | grep -F "$ts_uid" | cut -f2- -d' '
}
create_groups() {
echo "$friends" | jq -r '.gameid' | sort -u | while read -r gameid
do
if [ "$gameid" = "null" ]; then
continue
fi
game_name=$(echo $friends | jq -r --arg gameid "$gameid" 'select(.gameid == $gameid) | .gameextrainfo' | head -n 1)
players=$(echo $friends | jq -r --arg gameid "$gameid" 'select(.gameid == $gameid) | .steamid' | paste -sd ',')
jq -cn --argjson players "[$players]" --arg name "$game_name" --arg id "$gameid" '{id: $id, name: $name, players: $players}'
done
players=$(echo "$friends" | jq -r 'select(.gameid == null) | .steamid' | paste -sd ',')
jq -cn --argjson players "[$players]" '{id: null, name: "No game", players: $players}'
}
create_prompt() {
local groups="$1"
index=0
echo "$groups" | while read -r group
do
echo "$index $(echo "$group" | jq -r '.name')"
echo "$group" | jq -r '.players[]' | while read -r steamid
do
ts_name=$(steamid_to_tsname "$steamid")
echo "$index $ts_name"
done
index=$((index + 1))
done
}
groups=$(create_groups)
prompt=$(create_prompt "$groups")
selected=$(echo "$prompt" | $DMENU)
if [ -z "$selected" ]; then
exit 1
fi
target_channel=$(teamspeak-query-lib channels | $DMENU --prompt "Channel" || true)
if [ -z "$target_channel" ]; then
target_channel=$(teamspeak-query-lib channels --only-empty | head -n 1)
fi
selected_index=$(echo "$selected" | awk '{print $1}')
prefix="$selected_index "
readarray -t clients < <(echo "$prompt" | grep "^$prefix" | awk '{print $2}')
teamspeak-query-lib move --strict-client --strict-channel "$target_channel" "${clients[@]}"