Add event listener with JSON output (WIP) Add notifier on movement events Refactor Parameter and ParameterList (still shit)
This commit is contained in:
parent
2c0a8ab616
commit
d8cdc2bb11
14 changed files with 338 additions and 186 deletions
src
34
src/cli.rs
34
src/cli.rs
|
@ -1,8 +1,8 @@
|
|||
use clap::{Args, Parser, Subcommand};
|
||||
use telnet::Telnet;
|
||||
|
||||
use crate::parameter::{Parameter, ParameterList};
|
||||
use crate::models::Channel;
|
||||
use crate::parameter::ParameterList;
|
||||
use crate::models::{Channel, EventType};
|
||||
use crate::models::Client;
|
||||
use crate::utils::SendTextMessageTarget;
|
||||
use crate::wrappers;
|
||||
|
@ -23,6 +23,7 @@ pub enum Commands {
|
|||
Message(MessageArgs),
|
||||
Move(MoveArgs),
|
||||
Update(UpdateArgs),
|
||||
Events(EventArgs),
|
||||
}
|
||||
|
||||
#[derive(Args)]
|
||||
|
@ -78,6 +79,11 @@ pub struct UpdateArgs {
|
|||
speakers: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Args)]
|
||||
pub struct EventArgs {
|
||||
pub event: Vec<EventType>,
|
||||
}
|
||||
|
||||
impl FetchArgs {
|
||||
pub fn want_channel(&self) -> bool {
|
||||
self.channel.is_some()
|
||||
|
@ -89,14 +95,14 @@ impl FetchArgs {
|
|||
|
||||
pub fn channel(&self, connection: &mut Telnet) -> Result<Option<Channel>, String> {
|
||||
if let Some(channel) = &self.channel {
|
||||
wrappers::find_channel(connection, channel, self.strict_channel)
|
||||
wrappers::find_channel(connection, "channel_name", channel, self.strict_channel)
|
||||
} else {
|
||||
Err("No channel specified.".to_string())
|
||||
}
|
||||
}
|
||||
pub fn client(&self, connection: &mut Telnet) -> Result<Option<Client>, String> {
|
||||
if let Some(client) = &self.client {
|
||||
wrappers::find_client(connection, client, self.strict_client)
|
||||
wrappers::find_client(connection, "client_nickname", client, self.strict_client)
|
||||
} else {
|
||||
Err("No client specified.".to_string())
|
||||
}
|
||||
|
@ -108,7 +114,7 @@ impl MessageArgs {
|
|||
if self.server {
|
||||
Ok(SendTextMessageTarget::Server)
|
||||
} else if let Some(client) = &self.client {
|
||||
if let Some(client) = wrappers::find_client(connection, client, self.strict_client)? {
|
||||
if let Some(client) = wrappers::find_client(connection, "client_nickname", client, self.strict_client)? {
|
||||
return Ok(SendTextMessageTarget::Client(client));
|
||||
}
|
||||
return Err("Could not find client.".to_string());
|
||||
|
@ -120,12 +126,12 @@ impl MessageArgs {
|
|||
|
||||
impl MoveArgs {
|
||||
pub fn channel(&self, connection: &mut Telnet) -> Result<Option<Channel>, String> {
|
||||
wrappers::find_channel(connection, &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> {
|
||||
match &self.client {
|
||||
Some(client) => {
|
||||
wrappers::find_client(connection, client, self.strict_client)
|
||||
wrappers::find_client(connection, "client_nickname", client, self.strict_client)
|
||||
}
|
||||
None => {
|
||||
match wrappers::find_self(connection) {
|
||||
|
@ -139,25 +145,25 @@ impl MoveArgs {
|
|||
|
||||
impl UpdateArgs {
|
||||
pub fn to_parameter_list(&self) -> ParameterList {
|
||||
let mut params: ParameterList = Vec::new();
|
||||
let mut params: ParameterList = ParameterList::new();
|
||||
|
||||
if let Some(name) = &self.name {
|
||||
params.push(Parameter::new("client_nickname", name));
|
||||
params.insert(String::from("client_nickname"), name.clone());
|
||||
}
|
||||
|
||||
if let Some(away) = &self.away {
|
||||
params.push(Parameter::new("client_away_message", away));
|
||||
params.push(Parameter::new("client_away", "1"));
|
||||
params.insert(String::from("client_away_message"), away.clone());
|
||||
params.insert(String::from("client_away"), String::from("1"));
|
||||
}
|
||||
if self.back {
|
||||
params.push(Parameter::new("client_away", "0"));
|
||||
params.insert(String::from("client_away"), String::from("0"));
|
||||
}
|
||||
|
||||
if let Some(microphone) = self.microphone {
|
||||
params.push(Parameter::new("client_input_muted", &u8::from(!microphone).to_string()));
|
||||
params.insert(String::from("client_input_muted"), u8::from(!microphone).to_string());
|
||||
}
|
||||
if let Some(speakers) = self.speakers {
|
||||
params.push(Parameter::new("client_output_muted", &u8::from(!speakers).to_string()));
|
||||
params.insert(String::from("client_output_muted"), u8::from(!speakers).to_string());
|
||||
}
|
||||
|
||||
params
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue