pub struct Bot { /* private fields */ }Expand description
Implementations§
Source§impl Bot
impl Bot
Sourcepub fn new<S: Into<String>>(
nickname: S,
address: S,
replace_invalid_utf8: bool,
) -> Self
pub fn new<S: Into<String>>( nickname: S, address: S, replace_invalid_utf8: bool, ) -> Self
Constructs a new Bot instance.
Examples found in repository?
More examples
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}Sourcepub fn on_join(&mut self, callback: JoinCallback) -> Option<JoinCallback>
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
Sourcepub fn on_exit(&mut self, callback: ExitCallback) -> Option<ExitCallback>
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
Sourcepub fn on_pose(&mut self, callback: PoseCallback) -> Option<PoseCallback>
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
Sourcepub fn on_talk(&mut self, callback: TalkCallback) -> Option<TalkCallback>
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?
More examples
Sourcepub async fn run(self) -> Result<((Receiver, Sender), BotData), RuntimeError>
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?
More examples
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more