Add events and refactor

Add event listener with JSON output (WIP)
Add notifier on movement events
Refactor Parameter and ParameterList (still shit)
This commit is contained in:
Tobias Reisinger 2024-03-05 03:52:30 +01:00
parent 2c0a8ab616
commit d8cdc2bb11
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
14 changed files with 338 additions and 186 deletions

View file

@ -3,8 +3,9 @@ use std::process::exit;
use telnet::Telnet;
use crate::cli::Commands;
use crate::models::Channel;
use crate::models::{Channel, Event};
use crate::models::Client;
use crate::response::Response;
mod wrappers;
mod commands;
@ -49,8 +50,6 @@ fn main() {
wrappers::skip_welcome(&mut connection);
wrappers::login(&mut connection);
// You can check for the existence of subcommands, and if found use their
// matches just as you would the top level cmd
match cli {
@ -154,5 +153,35 @@ fn main() {
}
}
}
Commands::Events(args) => {
for event in args.event {
if commands::clientnotifyregister(&mut connection, 1, event).is_err() {
println!("Failed to register event listener.");
exit(1);
}
}
loop {
match commands::read_response(&mut connection, true, String::new()) {
Ok(response) => {
if let Response::Event(event_type, params) = response {
let event = Event::new(&mut connection, event_type, params);
match serde_json::to_string(&event) {
Ok(json) => println!("{}", json),
Err(_) => {
// TODO: Handle error
}
}
}
}
Err(_) => {
// TODO: Handle error
}
}
}
}
}
}