bot_server_client 1.0.0

Library to interact with the core of my bot
Documentation

Simple library to interact with my bot and build things like a discord_client

Example

extern crate bot_server_client;
use bot_server_client::client::connection::{Connection};
use bot_server_client::client::protocol::*;
use bot_server_client::helper::{ConfigGetHelper, TmpFileHelper};
use lazy_static::lazy_static;
use std::sync::Mutex;

lazy_static! {
    static ref CFG: Mutex<ConfigGetHelper> = Mutex::new(ConfigGetHelper::new());
    static ref TMP: Mutex<TmpFileHelper> = Mutex::new(TmpFileHelper::new());
}


struct PacketHandlers {
}

impl bot_server_client::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();
}
}