From e25a13e386af7cc5a3c21155b61f4d06b68497cf Mon Sep 17 00:00:00 2001 From: poslop Date: Wed, 7 Dec 2022 10:25:34 -0600 Subject: [PATCH] messages from server over 4k charcters are now cut to only 4k --- readme.md | 3 ++- src/main.rs | 4 +++- src/mindus.rs | 10 ++++------ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/readme.md b/readme.md index 57aa37c..0e83f16 100644 --- a/readme.md +++ b/readme.md @@ -32,4 +32,5 @@ Check the template for details about each setting ## Todo - Better error handling -- handle large responses from mindus server \ No newline at end of file +- handle large responses from mindus server +- make things modular diff --git a/src/main.rs b/src/main.rs index e532c5b..3cc5772 100644 --- a/src/main.rs +++ b/src/main.rs @@ -67,11 +67,13 @@ async fn main() { .await .expect("Error creating client"); + println!("Discord Bot Connected!!"); + { let mut data = client.data.write().await; data.insert::(sock); data.insert::(conf) - } + } if let Err(why) = client.start().await { println!("An error occurred while running the client: {:?} \n Check that there is a bot token set in config", why); diff --git a/src/mindus.rs b/src/mindus.rs index 9422fef..dd013cc 100644 --- a/src/mindus.rs +++ b/src/mindus.rs @@ -13,8 +13,8 @@ pub struct TcpSock { impl TcpSock { pub fn new(ip: String, port: String) -> std::io::Result { let stream = TcpStream::connect(format!("{}:{}", ip, port)).expect("Tcp connection fail"); - stream.set_read_timeout(Some(Duration::from_millis(200)))?; - + stream.set_read_timeout(Some(Duration::from_millis(25)))?; + println!("Socket Connected!!"); Ok(TcpSock { stream }) } } @@ -60,15 +60,14 @@ pub fn cons_rw(sock: &TcpSock, input: &str) -> String { Err(_) => break(), }; } - println!("{}", output); output = String::from_utf8(strip_ansi_escapes::strip(&output).unwrap()).unwrap(); + output.truncate(4000); output } pub async fn init_conf() -> Config { - let mut toml_file = OpenOptions::new() .read(true) .write(true) @@ -79,13 +78,12 @@ pub async fn init_conf() -> Config { toml_file.read_to_string(&mut toml_str).unwrap(); - println!("{}", toml_str); - let config: Config = toml::from_str(&toml_str).expect("unable to fill Config struct"); config } + fn toml_make() -> File { println!("initializing config"); let mut toml_file = OpenOptions::new()