```rs extern crate botserverclient; use botserverclient::client::connection::{Connection}; use botserverclient::client::protocol::*; use botserverclient::helper::{ConfigGetHelper, TmpFileHelper}; use lazystatic::lazystatic; use std::sync::Mutex;
lazy_static! {
static ref CFG: Mutex
struct PacketHandlers { }
impl botserverclient::client::connection::PacketHandlers for PacketHandlers { fn message_send(&self, pkg: &MessageSend) { println!("MSG {} {}", pkg.message, pkg.id); }
fn message_send_ack(&self, pkg: &MessageSendAck) {
println!("ACK {}", pkg.id);
}
fn internal_error(&self, pkg: &InternalError) {
println!("ERR {} {}", pkg.message, pkg.cause);
}
fn config_get_response(&self, pkg: &ConfigGetResponse) {
CFG.lock().unwrap().config_get_response(pkg);
}
fn auth_response(&self, pkg: &AuthResponse) {
println!("AUTH {}", pkg.success);
}
fn message_send_media(&self, pkg: &MessageSendMedia) {
println!("MSG {:?} {} {}", pkg._type, pkg.path, pkg.id);
}
fn set_bot_status(&self, pkg: &SetBotStatus) {
println!("STATUS {}", pkg.status);
}
fn tmp_file_response(&self, pkg: &TmpFileResponse) {
TMP.lock().unwrap().tmp_file_response(pkg);
}
}
fn main() { let connection = Connection::new("ws://127.0.0.1:8080".to_owned(), Box::new(PacketHandlers {})); connection.authenticate("thebestbot"); connection.log("rust", "hewoo");
connection.tmp_file_request("txt", 1000 * 10);
connection.on_message("fox!ping", "rust", "rust", Option::None, Option::None, Option::None, 69);
connection.on_message("fox!fox", "rust", "rust", Option::None, Option::None, Option::None, 69);
CFG.lock().unwrap().request(&connection, "websocket", "port");
loop {
match CFG.lock().unwrap().data() {
None => {},
Some(s) => {
println!("{}", s);
break;
}
}
}
TMP.lock().unwrap().request(&connection, "txt", 1000);
loop {
match TMP.lock().unwrap().data() {
None => {},
Some(s) => {
println!("{}", s);
break;
}
}
}
connection.await_exit();
} } ```