Add quick action

This commit is contained in:
Tobias Reisinger 2023-11-27 20:24:38 +01:00
parent ad58ab9bdd
commit 1f6d175a86
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
2 changed files with 67 additions and 94 deletions

View file

@ -42,143 +42,108 @@ pub fn login(connection: &mut Telnet) {
}
pub fn get_channels(connection: &mut Telnet, spacers: bool) -> Result<Vec<Channel>, String> {
match commands::channellist(connection) {
Ok(response) => {
match response {
Response::DataList(parameter_lists) => {
let channels: Vec<Channel> = parameter_lists.iter()
.map(|params| Channel::from(params.clone()))
.collect();
let mut channels = Channel::sort_list(channels);
if !spacers {
channels.retain(|c| !c.is_spacer());
}
Ok(channels)
}
_ => Err(String::from("Received unexpected models from Teamspeak."))
match commands::channellist(connection)? {
Response::DataList(parameter_lists) => {
let channels: Vec<Channel> = parameter_lists.iter()
.map(|params| Channel::from(params.clone()))
.collect();
let mut channels = Channel::sort_list(channels);
if !spacers {
channels.retain(|c| !c.is_spacer());
}
Ok(channels)
}
Err(msg) => Err(msg)
_ => Err(String::from("Received unexpected models from Teamspeak."))
}
}
pub fn find_channel(connection: &mut Telnet, name: &str, strict: bool) -> Result<Option<Channel>, String> {
match commands::channellist(connection) {
Ok(response) => {
match response {
Response::DataList(parameter_lists) => {
match parameter::parameter_list_find(&parameter_lists, "channel_name", name, strict) {
Some(params) => {
Ok(Some(Channel::from(params)))
}
None => {
Ok(None)
}
}
match commands::channellist(connection)? {
Response::DataList(parameter_lists) => {
match parameter::parameter_list_find(&parameter_lists, "channel_name", name, strict) {
Some(params) => {
Ok(Some(Channel::from(params)))
}
None => {
Ok(None)
}
_ => Err(String::from("Received unexpected models from Teamspeak."))
}
}
Err(msg) => Err(msg)
_ => Err(String::from("Received unexpected models from Teamspeak."))
}
}
pub fn get_clients(connection: &mut Telnet) -> Result<Vec<Client>, String> {
match commands::clientlist(connection) {
Ok(response) => {
match response {
Response::DataList(parameter_lists) => {
let mut clients: Vec<Client> = parameter_lists.iter()
.map(|params| Client::from(params.clone()))
.collect();
match commands::clientlist(connection)? {
Response::DataList(parameter_lists) => {
let mut clients: Vec<Client> = parameter_lists.iter()
.map(|params| Client::from(params.clone()))
.collect();
clients.sort_by(|a, b| a.client_nickname.cmp(&b.client_nickname));
clients.sort_by(|a, b| a.client_nickname.cmp(&b.client_nickname));
Ok(clients)
}
_ => Err(String::from("Received unexpected models from Teamspeak."))
}
Ok(clients)
}
Err(msg) => Err(msg)
_ => Err(String::from("Received unexpected models from Teamspeak."))
}
}
pub fn find_client(connection: &mut Telnet, name: &str, strict: bool) -> Result<Option<Client>, String> {
match commands::clientlist(connection) {
Ok(response) => {
match response {
Response::DataList(parameter_lists) => {
match parameter::parameter_list_find(&parameter_lists, "client_nickname", name, strict) {
Some(params) => {
Ok(Some(Client::from(params)))
}
None => {
Ok(None)
}
}
match commands::clientlist(connection)? {
Response::DataList(parameter_lists) => {
match parameter::parameter_list_find(&parameter_lists, "client_nickname", name, strict) {
Some(params) => {
Ok(Some(Client::from(params)))
}
None => {
Ok(None)
}
_ => Err(String::from("Received unexpected models from Teamspeak."))
}
}
Err(msg) => Err(msg)
_ => Err(String::from("Received unexpected models from Teamspeak."))
}
}
pub fn get_channel_clients(connection: &mut Telnet, channel: &Channel) -> Result<Vec<Client>, String> {
match commands::clientlist(connection) {
Ok(response) => {
match response {
Response::DataList(parameter_lists) => {
let mut clients: Vec<Client> = Vec::new();
for client_params in parameter_list_find_all(&parameter_lists, "cid", &channel.cid.to_string(), true) {
clients.push(Client::from(client_params));
}
Ok(clients)
}
_ => Err(String::from("Received unexpected models from Teamspeak."))
match commands::clientlist(connection)? {
Response::DataList(parameter_lists) => {
let mut clients: Vec<Client> = Vec::new();
for client_params in parameter_list_find_all(&parameter_lists, "cid", &channel.cid.to_string(), true) {
clients.push(Client::from(client_params));
}
Ok(clients)
}
Err(msg) => Err(msg)
_ => Err(String::from("Received unexpected models from Teamspeak."))
}
}
fn get_self_clid(connection: &mut Telnet) -> Result<String, String> {
match commands::whoami(connection) {
Ok(response) => {
match response {
Response::Data(params) => {
match parameter::parameter_find(&params, "clid") {
None => Err(String::from("Could not find clid in models from Teamspeak.")),
Some(param) => Ok(param.value)
}
}
_ => Err(String::from("Received unexpected models from Teamspeak for whoami."))
match commands::whoami(connection)? {
Response::Data(params) => {
match parameter::parameter_find(&params, "clid") {
None => Err(String::from("Could not find clid in models from Teamspeak.")),
Some(param) => Ok(param.value)
}
}
Err(msg) => Err(msg)
_ => Err(String::from("Received unexpected models from Teamspeak for whoami."))
}
}
pub fn find_self(connection: &mut Telnet) -> Result<Client, String> {
let clid = get_self_clid(connection)?;
match commands::clientlist(connection) {
Ok(response) => {
match response {
Response::DataList(parameter_lists) => {
match parameter::parameter_list_find(&parameter_lists, "clid", &clid, false) {
Some(params) => {
Ok(Client::from(params))
}
None => {
Err(String::from("Could not find self in models from Teamspeak."))
}
}
match commands::clientlist(connection)? {
Response::DataList(parameter_lists) => {
match parameter::parameter_list_find(&parameter_lists, "clid", &clid, false) {
Some(params) => {
Ok(Client::from(params))
}
None => {
Err(String::from("Could not find self in models from Teamspeak."))
}
_ => Err(String::from("Received unexpected models from Teamspeak for clientlist."))
}
}
Err(msg) => Err(msg)
_ => Err(String::from("Received unexpected models from Teamspeak for clientlist."))
}
}

View file

@ -1,6 +1,7 @@
#!/usr/bin/env sh
actions="move
actions="quick
move
fetch-client
fetch-channel
away
@ -37,6 +38,13 @@ _ts_control_fetch() {
}
case $action in
"quick")
action=$($DMENU < "$XDG_CONFIG_HOME/ts-control-quick")
if [ -z "$action" ]; then
exit 1
fi
eval "teamspeak-query-lib $action"
;;
"move")
_ts_control_move_self
;;