messages from server over 4k charcters are now cut to only 4k

This commit is contained in:
poslop
2022-12-07 10:25:34 -06:00
parent 5fcd29ac56
commit e25a13e386
3 changed files with 9 additions and 8 deletions

View File

@@ -33,3 +33,4 @@ Check the template for details about each setting
## Todo
- Better error handling
- handle large responses from mindus server
- make things modular

View File

@@ -67,6 +67,8 @@ async fn main() {
.await
.expect("Error creating client");
println!("Discord Bot Connected!!");
{
let mut data = client.data.write().await;
data.insert::<TcpSock>(sock);

View File

@@ -13,8 +13,8 @@ pub struct TcpSock {
impl TcpSock {
pub fn new(ip: String, port: String) -> std::io::Result<Self> {
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()