This commit is contained in:
parent
6b7b549029
commit
6dddeb9c2e
8 changed files with 91 additions and 17 deletions
64
control_src/split_command.sh
Normal file
64
control_src/split_command.sh
Normal 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[@]}"
|
Loading…
Add table
Add a link
Reference in a new issue