Add quick action
This commit is contained in:
		
							parent
							
								
									ad58ab9bdd
								
							
						
					
					
						commit
						1f6d175a86
					
				
					 2 changed files with 67 additions and 94 deletions
				
			
		|  | @ -42,9 +42,7 @@ pub fn login(connection: &mut Telnet) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| pub fn get_channels(connection: &mut Telnet, spacers: bool) -> Result<Vec<Channel>, String> { | pub fn get_channels(connection: &mut Telnet, spacers: bool) -> Result<Vec<Channel>, String> { | ||||||
|     match commands::channellist(connection) { |     match commands::channellist(connection)? { | ||||||
|         Ok(response) => { |  | ||||||
|             match response { |  | ||||||
|         Response::DataList(parameter_lists) => { |         Response::DataList(parameter_lists) => { | ||||||
|             let channels: Vec<Channel> = parameter_lists.iter() |             let channels: Vec<Channel> = parameter_lists.iter() | ||||||
|                 .map(|params| Channel::from(params.clone())) |                 .map(|params| Channel::from(params.clone())) | ||||||
|  | @ -58,14 +56,9 @@ pub fn get_channels(connection: &mut Telnet, spacers: bool) -> Result<Vec<Channe | ||||||
|         _ => Err(String::from("Received unexpected models from Teamspeak.")) |         _ => Err(String::from("Received unexpected models from Teamspeak.")) | ||||||
|     } |     } | ||||||
| } | } | ||||||
|         Err(msg) => Err(msg) |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| pub fn find_channel(connection: &mut Telnet, name: &str, strict: bool) -> Result<Option<Channel>, String> { | pub fn find_channel(connection: &mut Telnet, name: &str, strict: bool) -> Result<Option<Channel>, String> { | ||||||
|     match commands::channellist(connection) { |     match commands::channellist(connection)? { | ||||||
|         Ok(response) => { |  | ||||||
|             match response { |  | ||||||
|         Response::DataList(parameter_lists) => { |         Response::DataList(parameter_lists) => { | ||||||
|             match parameter::parameter_list_find(¶meter_lists, "channel_name", name, strict) { |             match parameter::parameter_list_find(¶meter_lists, "channel_name", name, strict) { | ||||||
|                 Some(params) => { |                 Some(params) => { | ||||||
|  | @ -79,14 +72,9 @@ pub fn find_channel(connection: &mut Telnet, name: &str, strict: bool) -> Result | ||||||
|         _ => Err(String::from("Received unexpected models from Teamspeak.")) |         _ => Err(String::from("Received unexpected models from Teamspeak.")) | ||||||
|     } |     } | ||||||
| } | } | ||||||
|         Err(msg) => Err(msg) |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| pub fn get_clients(connection: &mut Telnet) -> Result<Vec<Client>, String> { | pub fn get_clients(connection: &mut Telnet) -> Result<Vec<Client>, String> { | ||||||
|     match commands::clientlist(connection) { |     match commands::clientlist(connection)? { | ||||||
|         Ok(response) => { |  | ||||||
|             match response { |  | ||||||
|         Response::DataList(parameter_lists) => { |         Response::DataList(parameter_lists) => { | ||||||
|             let mut clients: Vec<Client> = parameter_lists.iter() |             let mut clients: Vec<Client> = parameter_lists.iter() | ||||||
|                 .map(|params| Client::from(params.clone())) |                 .map(|params| Client::from(params.clone())) | ||||||
|  | @ -99,14 +87,9 @@ pub fn get_clients(connection: &mut Telnet) -> Result<Vec<Client>, String> { | ||||||
|         _ => Err(String::from("Received unexpected models from Teamspeak.")) |         _ => Err(String::from("Received unexpected models from Teamspeak.")) | ||||||
|     } |     } | ||||||
| } | } | ||||||
|         Err(msg) => Err(msg) |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| pub fn find_client(connection: &mut Telnet, name: &str, strict: bool) -> Result<Option<Client>, String> { | pub fn find_client(connection: &mut Telnet, name: &str, strict: bool) -> Result<Option<Client>, String> { | ||||||
|     match commands::clientlist(connection) { |     match commands::clientlist(connection)? { | ||||||
|         Ok(response) => { |  | ||||||
|             match response { |  | ||||||
|         Response::DataList(parameter_lists) => { |         Response::DataList(parameter_lists) => { | ||||||
|             match parameter::parameter_list_find(¶meter_lists, "client_nickname", name, strict) { |             match parameter::parameter_list_find(¶meter_lists, "client_nickname", name, strict) { | ||||||
|                 Some(params) => { |                 Some(params) => { | ||||||
|  | @ -120,14 +103,9 @@ pub fn find_client(connection: &mut Telnet, name: &str, strict: bool) -> Result< | ||||||
|         _ => Err(String::from("Received unexpected models from Teamspeak.")) |         _ => Err(String::from("Received unexpected models from Teamspeak.")) | ||||||
|     } |     } | ||||||
| } | } | ||||||
|         Err(msg) => Err(msg) |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| pub fn get_channel_clients(connection: &mut Telnet, channel: &Channel) -> Result<Vec<Client>, String> { | pub fn get_channel_clients(connection: &mut Telnet, channel: &Channel) -> Result<Vec<Client>, String> { | ||||||
|     match commands::clientlist(connection) { |     match commands::clientlist(connection)? { | ||||||
|         Ok(response) => { |  | ||||||
|             match response { |  | ||||||
|         Response::DataList(parameter_lists) => { |         Response::DataList(parameter_lists) => { | ||||||
|             let mut clients: Vec<Client> = Vec::new(); |             let mut clients: Vec<Client> = Vec::new(); | ||||||
|             for client_params in parameter_list_find_all(¶meter_lists, "cid", &channel.cid.to_string(), true) { |             for client_params in parameter_list_find_all(¶meter_lists, "cid", &channel.cid.to_string(), true) { | ||||||
|  | @ -138,14 +116,9 @@ pub fn get_channel_clients(connection: &mut Telnet, channel: &Channel) -> Result | ||||||
|         _ => Err(String::from("Received unexpected models from Teamspeak.")) |         _ => Err(String::from("Received unexpected models from Teamspeak.")) | ||||||
|     } |     } | ||||||
| } | } | ||||||
|         Err(msg) => Err(msg) |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| fn get_self_clid(connection: &mut Telnet) -> Result<String, String> { | fn get_self_clid(connection: &mut Telnet) -> Result<String, String> { | ||||||
|     match commands::whoami(connection) { |     match commands::whoami(connection)? { | ||||||
|         Ok(response) => { |  | ||||||
|             match response { |  | ||||||
|         Response::Data(params) => { |         Response::Data(params) => { | ||||||
|             match parameter::parameter_find(¶ms, "clid") { |             match parameter::parameter_find(¶ms, "clid") { | ||||||
|                 None => Err(String::from("Could not find clid in models from Teamspeak.")), |                 None => Err(String::from("Could not find clid in models from Teamspeak.")), | ||||||
|  | @ -155,16 +128,11 @@ fn get_self_clid(connection: &mut Telnet) -> Result<String, String> { | ||||||
|         _ => Err(String::from("Received unexpected models from Teamspeak for whoami.")) |         _ => Err(String::from("Received unexpected models from Teamspeak for whoami.")) | ||||||
|     } |     } | ||||||
| } | } | ||||||
|         Err(msg) => Err(msg) |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| pub fn find_self(connection: &mut Telnet) -> Result<Client, String> { | pub fn find_self(connection: &mut Telnet) -> Result<Client, String> { | ||||||
|     let clid = get_self_clid(connection)?; |     let clid = get_self_clid(connection)?; | ||||||
| 
 | 
 | ||||||
|     match commands::clientlist(connection) { |     match commands::clientlist(connection)? { | ||||||
|         Ok(response) => { |  | ||||||
|             match response { |  | ||||||
|         Response::DataList(parameter_lists) => { |         Response::DataList(parameter_lists) => { | ||||||
|             match parameter::parameter_list_find(¶meter_lists, "clid", &clid, false) { |             match parameter::parameter_list_find(¶meter_lists, "clid", &clid, false) { | ||||||
|                 Some(params) => { |                 Some(params) => { | ||||||
|  | @ -178,9 +146,6 @@ pub fn find_self(connection: &mut Telnet) -> Result<Client, String> { | ||||||
|         _ => Err(String::from("Received unexpected models from Teamspeak for clientlist.")) |         _ => Err(String::from("Received unexpected models from Teamspeak for clientlist.")) | ||||||
|     } |     } | ||||||
| } | } | ||||||
|         Err(msg) => Err(msg) |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| pub fn fetch_client(connection: &mut Telnet, clients: &[Client]) -> Result<Response, String> { | pub fn fetch_client(connection: &mut Telnet, clients: &[Client]) -> Result<Response, String> { | ||||||
|     let cid = find_self(connection)?.cid; |     let cid = find_self(connection)?.cid; | ||||||
|  |  | ||||||
							
								
								
									
										10
									
								
								ts-control
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								ts-control
									
										
									
									
									
								
							|  | @ -1,6 +1,7 @@ | ||||||
| #!/usr/bin/env sh | #!/usr/bin/env sh | ||||||
| 
 | 
 | ||||||
| actions="move | actions="quick | ||||||
|  | move | ||||||
| fetch-client | fetch-client | ||||||
| fetch-channel | fetch-channel | ||||||
| away | away | ||||||
|  | @ -37,6 +38,13 @@ _ts_control_fetch() { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| case $action in | 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") | 	"move") | ||||||
| 		_ts_control_move_self | 		_ts_control_move_self | ||||||
| 		;; | 		;; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue