Refactor naming
This commit is contained in:
parent
a9fd240bd3
commit
ad58ab9bdd
10 changed files with 66 additions and 62 deletions
src
|
@ -6,8 +6,8 @@ use telnet::Telnet;
|
|||
|
||||
use crate::{commands, parameter};
|
||||
use crate::parameter::{parameter_list_find_all, ParameterList};
|
||||
use crate::response::channel::ResponseChannel;
|
||||
use crate::response::client::ResponseClient;
|
||||
use crate::models::Channel;
|
||||
use crate::models::Client;
|
||||
use crate::response::Response;
|
||||
use crate::utils::SendTextMessageTarget;
|
||||
|
||||
|
@ -41,101 +41,101 @@ pub fn login(connection: &mut Telnet) {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_channels(connection: &mut Telnet, spacers: bool) -> Result<Vec<ResponseChannel>, String> {
|
||||
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<ResponseChannel> = parameter_lists.iter()
|
||||
.map(|params| ResponseChannel::from(params.clone()))
|
||||
let channels: Vec<Channel> = parameter_lists.iter()
|
||||
.map(|params| Channel::from(params.clone()))
|
||||
.collect();
|
||||
let mut channels = ResponseChannel::sort_list(channels);
|
||||
let mut channels = Channel::sort_list(channels);
|
||||
if !spacers {
|
||||
channels.retain(|c| !c.is_spacer());
|
||||
}
|
||||
Ok(channels)
|
||||
}
|
||||
_ => Err(String::from("Received unexpected response 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<ResponseChannel>, String> {
|
||||
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(¶meter_lists, "channel_name", name, strict) {
|
||||
Some(params) => {
|
||||
Ok(Some(ResponseChannel::from(params)))
|
||||
Ok(Some(Channel::from(params)))
|
||||
}
|
||||
None => {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => Err(String::from("Received unexpected response from Teamspeak."))
|
||||
_ => Err(String::from("Received unexpected models from Teamspeak."))
|
||||
}
|
||||
}
|
||||
Err(msg) => Err(msg)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_clients(connection: &mut Telnet) -> Result<Vec<ResponseClient>, String> {
|
||||
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<ResponseClient> = parameter_lists.iter()
|
||||
.map(|params| ResponseClient::from(params.clone()))
|
||||
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));
|
||||
|
||||
Ok(clients)
|
||||
}
|
||||
_ => Err(String::from("Received unexpected response 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<ResponseClient>, String> {
|
||||
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(¶meter_lists, "client_nickname", name, strict) {
|
||||
Some(params) => {
|
||||
Ok(Some(ResponseClient::from(params)))
|
||||
Ok(Some(Client::from(params)))
|
||||
}
|
||||
None => {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => Err(String::from("Received unexpected response from Teamspeak."))
|
||||
_ => Err(String::from("Received unexpected models from Teamspeak."))
|
||||
}
|
||||
}
|
||||
Err(msg) => Err(msg)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_channel_clients(connection: &mut Telnet, channel: &ResponseChannel) -> Result<Vec<ResponseClient>, String> {
|
||||
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<ResponseClient> = 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) {
|
||||
clients.push(ResponseClient::from(client_params));
|
||||
clients.push(Client::from(client_params));
|
||||
}
|
||||
Ok(clients)
|
||||
}
|
||||
_ => Err(String::from("Received unexpected response from Teamspeak."))
|
||||
_ => Err(String::from("Received unexpected models from Teamspeak."))
|
||||
}
|
||||
}
|
||||
Err(msg) => Err(msg)
|
||||
|
@ -148,18 +148,18 @@ fn get_self_clid(connection: &mut Telnet) -> Result<String, String> {
|
|||
match response {
|
||||
Response::Data(params) => {
|
||||
match parameter::parameter_find(¶ms, "clid") {
|
||||
None => Err(String::from("Could not find clid in response from Teamspeak.")),
|
||||
None => Err(String::from("Could not find clid in models from Teamspeak.")),
|
||||
Some(param) => Ok(param.value)
|
||||
}
|
||||
}
|
||||
_ => Err(String::from("Received unexpected response 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<ResponseClient, String> {
|
||||
pub fn find_self(connection: &mut Telnet) -> Result<Client, String> {
|
||||
let clid = get_self_clid(connection)?;
|
||||
|
||||
match commands::clientlist(connection) {
|
||||
|
@ -168,28 +168,28 @@ pub fn find_self(connection: &mut Telnet) -> Result<ResponseClient, String> {
|
|||
Response::DataList(parameter_lists) => {
|
||||
match parameter::parameter_list_find(¶meter_lists, "clid", &clid, false) {
|
||||
Some(params) => {
|
||||
Ok(ResponseClient::from(params))
|
||||
Ok(Client::from(params))
|
||||
}
|
||||
None => {
|
||||
Err(String::from("Could not find self in response from Teamspeak."))
|
||||
Err(String::from("Could not find self in models from Teamspeak."))
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => Err(String::from("Received unexpected response 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: &[ResponseClient]) -> Result<Response, String> {
|
||||
pub fn fetch_client(connection: &mut Telnet, clients: &[Client]) -> Result<Response, String> {
|
||||
let cid = find_self(connection)?.cid;
|
||||
let clid_list: Vec<&i32> = clients.iter().map(|c| &c.clid).collect();
|
||||
|
||||
commands::clientmove(connection, &cid, clid_list)
|
||||
}
|
||||
|
||||
pub fn fetch_channel(connection: &mut Telnet, channel: ResponseChannel) -> Result<Response, String> {
|
||||
pub fn fetch_channel(connection: &mut Telnet, channel: Channel) -> Result<Response, String> {
|
||||
let cid = find_self(connection)?.cid;
|
||||
|
||||
let clients = get_channel_clients(connection, &channel)?;
|
||||
|
@ -198,7 +198,7 @@ pub fn fetch_channel(connection: &mut Telnet, channel: ResponseChannel) -> Resul
|
|||
commands::clientmove(connection, &cid, clid_list)
|
||||
}
|
||||
|
||||
pub fn move_client(connection: &mut Telnet, channel: &ResponseChannel, clients: &[ResponseClient]) -> Result<Response, String> {
|
||||
pub fn move_client(connection: &mut Telnet, channel: &Channel, clients: &[Client]) -> Result<Response, String> {
|
||||
let clid_list: Vec<&i32> = clients.iter().map(|c| &c.clid).collect();
|
||||
|
||||
commands::clientmove(connection, &channel.cid, clid_list)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue