use std::sync::Arc;
use azalea_protocol::packets::game::{ServerboundGamePacket, s_interact::InteractionHand};
use tokio::sync::mpsc;
use crate::bot::account::BotAccount;
#[derive(Clone, Debug)]
pub enum BotCommand {
Chat(String),
SetDirection { yaw: f32, pitch: f32 },
SetPosition { x: f64, y: f64, z: f64 },
SwingArm(InteractionHand),
StartUseItem(InteractionHand),
ReleaseUseItem,
SendPacket(ServerboundGamePacket),
Disconnect,
Reconnect { server_host: String, server_port: u16, interval: u64 },
}
#[derive(Clone)]
pub struct BotTerminal {
pub account: Arc<BotAccount>,
pub cmd: mpsc::Sender<BotCommand>,
}
impl BotTerminal {
pub async fn send(&self, command: BotCommand) {
let _ = self.cmd.send(command).await;
}
pub async fn chat(&self, message: impl Into<String>) {
self.send(BotCommand::Chat(message.into())).await;
}
pub async fn disconnect(&self) {
self.send(BotCommand::Disconnect).await;
}
pub async fn reconnect(&self, server_host: impl Into<String>, server_port: u16, interval: u64) {
self
.send(BotCommand::Reconnect {
server_host: server_host.into(),
server_port,
interval,
})
.await;
}
}