This commit is contained in:
parent
6b7b549029
commit
6dddeb9c2e
8 changed files with 91 additions and 17 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -182,7 +182,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "teamspeak-query-lib"
|
name = "teamspeak-query-lib"
|
||||||
version = "0.1.6"
|
version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"serde",
|
"serde",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "teamspeak-query-lib"
|
name = "teamspeak-query-lib"
|
||||||
version = "0.1.6"
|
version = "0.2.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
actions=(
|
actions=(
|
||||||
"quick"
|
"quick"
|
||||||
"move"
|
"move"
|
||||||
|
"split"
|
||||||
"fetch-client"
|
"fetch-client"
|
||||||
"fetch-channel"
|
"fetch-channel"
|
||||||
"migrate"
|
"migrate"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
name: ts-control
|
name: ts-control
|
||||||
help: Teamspeak query lib utility script
|
help: Teamspeak query lib utility script
|
||||||
version: 0.1.0
|
version: 0.2.0
|
||||||
|
|
||||||
environment_variables:
|
environment_variables:
|
||||||
- name: ts3_client_api_key
|
- name: ts3_client_api_key
|
||||||
|
@ -11,6 +11,7 @@ commands:
|
||||||
- name: ask
|
- name: ask
|
||||||
default: force
|
default: force
|
||||||
- name: quick
|
- name: quick
|
||||||
|
- name: split
|
||||||
- name: move
|
- name: move
|
||||||
args:
|
args:
|
||||||
- name: channel
|
- name: channel
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
action=$($DMENU < "$XDG_CONFIG_HOME/ts-control-quick")
|
action=$($DMENU < "$XDG_CONFIG_HOME/ts-control/quick")
|
||||||
if [ -z "$action" ]; then
|
if [ -z "$action" ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
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[@]}"
|
23
src/cli.rs
23
src/cli.rs
|
@ -73,7 +73,7 @@ pub struct MoveArgs {
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
strict_channel: bool,
|
strict_channel: bool,
|
||||||
channel: String,
|
channel: String,
|
||||||
client: Option<String>,
|
clients: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Args)]
|
#[derive(Args)]
|
||||||
|
@ -148,17 +148,24 @@ impl MoveArgs {
|
||||||
pub fn channel(&self, connection: &mut Telnet) -> Result<Option<Channel>, String> {
|
pub fn channel(&self, connection: &mut Telnet) -> Result<Option<Channel>, String> {
|
||||||
wrappers::find_channel(connection, "channel_name", &self.channel, self.strict_channel)
|
wrappers::find_channel(connection, "channel_name", &self.channel, self.strict_channel)
|
||||||
}
|
}
|
||||||
pub fn client(&self, connection: &mut Telnet) -> Result<Option<Client>, String> {
|
pub fn clients(&self, connection: &mut Telnet) -> Result<Vec<Client>, String> {
|
||||||
match &self.client {
|
match self.clients.is_empty() {
|
||||||
Some(client) => {
|
true => {
|
||||||
wrappers::find_client(connection, "client_nickname", client, self.strict_client)
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
match wrappers::find_self(connection) {
|
match wrappers::find_self(connection) {
|
||||||
Ok(client) => Ok(Some(client)),
|
Ok(client) => Ok(vec![client]),
|
||||||
Err(msg) => Err(msg)
|
Err(msg) => Err(msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
false => {
|
||||||
|
let clients = self.clients.iter().map(|client_nickname| {
|
||||||
|
wrappers::find_client(connection, "client_nickname", client_nickname, self.strict_client)
|
||||||
|
.unwrap_or(None)
|
||||||
|
})
|
||||||
|
.filter(|result| result.is_some())
|
||||||
|
.map(|result| result.unwrap())
|
||||||
|
.collect();
|
||||||
|
Ok(clients)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -149,9 +149,10 @@ fn main() -> Result<(), Error> {
|
||||||
|
|
||||||
Commands::Move(args) => {
|
Commands::Move(args) => {
|
||||||
let channel = result_or_error(args.channel(&mut connection), "channel")?;
|
let channel = result_or_error(args.channel(&mut connection), "channel")?;
|
||||||
let client = result_or_error(args.client(&mut connection), "client")?;
|
let clients = args.clients(&mut connection)
|
||||||
|
.map_err(|msg| make_action_error("move clients", msg))?;
|
||||||
|
|
||||||
match wrappers::move_client(&mut connection, &channel, &[client]) {
|
match wrappers::move_client(&mut connection, &channel, &clients) {
|
||||||
Ok(resp) => println!("Successfully moved client: {}", resp),
|
Ok(resp) => println!("Successfully moved client: {}", resp),
|
||||||
Err(msg) => {
|
Err(msg) => {
|
||||||
return Err(make_action_error("move client", msg));
|
return Err(make_action_error("move client", msg));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue