Bot

Struct Bot 

Source
pub struct Bot { /* private fields */ }
Expand description

Provides highest level of abstraction.

Can be easily constructed with Bot::new and ran with Bot::run.

§Examples

§Creating a new bot and running it:

use asciicker_rs::y6::prelude::*;

let bot = Bot::new("bot", "ws://asciicker.com/ws/y6/", true);

bot.run();
loop {}

Implementations§

Source§

impl Bot

Source

pub fn new<S: Into<String>>( nickname: S, address: S, replace_invalid_utf8: bool, ) -> Self

Constructs a new Bot instance.

Examples found in repository?
examples/y6_chat_logger.rs (line 9)
8async fn main() {
9    let mut bot = Bot::new("player", "ws://asciicker.com/ws/y6/", true);
10    bot.on_talk(talk_callback);
11    let (threads, _data) = match bot.run().await {
12        Err(e) => panic!("Failed to run the bot: {:?}", e),
13        Ok(stuff) => stuff,
14    };
15    println!("{:?}", threads.0.thread.await);
16}
More examples
Hide additional examples
examples/y6_echo_bot.rs (line 9)
8async fn main() {
9    let mut bot = Bot::new("player", "ws://asciicker.com/ws/y6/", true);
10    bot.on_talk(talk_callback);
11    let (threads, _data) = match bot.run().await {
12        Err(e) => panic!("Failed to run the bot: {:?}", e),
13        Ok(stuff) => stuff,
14    };
15    println!("{:?}", threads.0.thread.await);
16}
examples/y6_rotating_bot.rs (line 5)
4async fn main() {
5    let bot = Bot::new("player", "ws://asciicker.com/ws/y6/", true);
6    let (threads, data) = match bot.run().await {
7        Err(e) => panic!("Failed to run the bot: {:?}", e),
8        Ok(stuff) => stuff,
9    };
10    let mut i: f32 = 0f32;
11    loop {
12        match *threads.0.is_finished.lock().await {
13            true => {
14                println!("{:?}", threads.0.thread.await);
15                return;
16            }
17            _ => {}
18        };
19        let mut bot = data.0.lock().await;
20        bot.pose.direction = i;
21        i += 0.01f32;
22        if i >= 360f32 {
23            i = 0f32;
24        }
25    }
26}
examples/y6_circling_bot.rs (line 7)
6async fn main() {
7    let bot = Bot::new("player", "ws://asciicker.com/ws/y6/", true);
8    let (threads, data) = match bot.run().await {
9        Err(e) => panic!("Failed to run the bot: {:?}", e),
10        Ok(stuff) => stuff,
11    };
12    let mut i = 0f32;
13    loop {
14        match *threads.0.is_finished.lock().await {
15            true => {
16                println!("{:?}", threads.0.thread.await);
17                return;
18            }
19            _ => {}
20        };
21        let mut bot = data.0.lock().await;
22        let x = i.cos() * RADIUS;
23        let y = i.sin() * RADIUS;
24        bot.pose.position = [x, y, 300f32];
25        i += 0.00001;
26        if i >= std::f32::consts::PI * 2f32 {
27            i = 0f32;
28        }
29    }
30}
Source

pub fn on_join(&mut self, callback: JoinCallback) -> Option<JoinCallback>

Replaces JoinCallback and returns [Some(JoinCallback)] if any was set already. [Some(JoinCallback)]: Option::Some

Source

pub fn on_exit(&mut self, callback: ExitCallback) -> Option<ExitCallback>

Replaces ExitCallback and returns [Some(ExitCallback)] if any was set already. [Some(ExitCallback)]: Option::Some

Source

pub fn on_pose(&mut self, callback: PoseCallback) -> Option<PoseCallback>

Replaces PoseCallback and returns [Some(PoseCallback)] if any was set already. [Some(PoseCallback)]: Option::Some

Source

pub fn on_talk(&mut self, callback: TalkCallback) -> Option<TalkCallback>

Replaces TalkCallback and returns [Some(TalkCallback)] if any was set already. [Some(TalkCallback)]: Option::Some

Examples found in repository?
examples/y6_chat_logger.rs (line 10)
8async fn main() {
9    let mut bot = Bot::new("player", "ws://asciicker.com/ws/y6/", true);
10    bot.on_talk(talk_callback);
11    let (threads, _data) = match bot.run().await {
12        Err(e) => panic!("Failed to run the bot: {:?}", e),
13        Ok(stuff) => stuff,
14    };
15    println!("{:?}", threads.0.thread.await);
16}
More examples
Hide additional examples
examples/y6_echo_bot.rs (line 10)
8async fn main() {
9    let mut bot = Bot::new("player", "ws://asciicker.com/ws/y6/", true);
10    bot.on_talk(talk_callback);
11    let (threads, _data) = match bot.run().await {
12        Err(e) => panic!("Failed to run the bot: {:?}", e),
13        Ok(stuff) => stuff,
14    };
15    println!("{:?}", threads.0.thread.await);
16}
Source

pub async fn run(self) -> Result<((Receiver, Sender), BotData), RuntimeError>

Runs the bot.

Spawns two threads: Receiver, Sender and returns them with BotData if connecting was successful.

Examples found in repository?
examples/y6_chat_logger.rs (line 11)
8async fn main() {
9    let mut bot = Bot::new("player", "ws://asciicker.com/ws/y6/", true);
10    bot.on_talk(talk_callback);
11    let (threads, _data) = match bot.run().await {
12        Err(e) => panic!("Failed to run the bot: {:?}", e),
13        Ok(stuff) => stuff,
14    };
15    println!("{:?}", threads.0.thread.await);
16}
More examples
Hide additional examples
examples/y6_echo_bot.rs (line 11)
8async fn main() {
9    let mut bot = Bot::new("player", "ws://asciicker.com/ws/y6/", true);
10    bot.on_talk(talk_callback);
11    let (threads, _data) = match bot.run().await {
12        Err(e) => panic!("Failed to run the bot: {:?}", e),
13        Ok(stuff) => stuff,
14    };
15    println!("{:?}", threads.0.thread.await);
16}
examples/y6_rotating_bot.rs (line 6)
4async fn main() {
5    let bot = Bot::new("player", "ws://asciicker.com/ws/y6/", true);
6    let (threads, data) = match bot.run().await {
7        Err(e) => panic!("Failed to run the bot: {:?}", e),
8        Ok(stuff) => stuff,
9    };
10    let mut i: f32 = 0f32;
11    loop {
12        match *threads.0.is_finished.lock().await {
13            true => {
14                println!("{:?}", threads.0.thread.await);
15                return;
16            }
17            _ => {}
18        };
19        let mut bot = data.0.lock().await;
20        bot.pose.direction = i;
21        i += 0.01f32;
22        if i >= 360f32 {
23            i = 0f32;
24        }
25    }
26}
examples/y6_circling_bot.rs (line 8)
6async fn main() {
7    let bot = Bot::new("player", "ws://asciicker.com/ws/y6/", true);
8    let (threads, data) = match bot.run().await {
9        Err(e) => panic!("Failed to run the bot: {:?}", e),
10        Ok(stuff) => stuff,
11    };
12    let mut i = 0f32;
13    loop {
14        match *threads.0.is_finished.lock().await {
15            true => {
16                println!("{:?}", threads.0.thread.await);
17                return;
18            }
19            _ => {}
20        };
21        let mut bot = data.0.lock().await;
22        let x = i.cos() * RADIUS;
23        let y = i.sin() * RADIUS;
24        bot.pose.position = [x, y, 300f32];
25        i += 0.00001;
26        if i >= std::f32::consts::PI * 2f32 {
27            i = 0f32;
28        }
29    }
30}

Auto Trait Implementations§

§

impl Freeze for Bot

§

impl RefUnwindSafe for Bot

§

impl Send for Bot

§

impl Sync for Bot

§

impl Unpin for Bot

§

impl UnwindSafe for Bot

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,