This repository has been archived on 2025-07-02. You can view files and clone it, but cannot push or open issues or pull requests.
UwUBot/src/utils/commands.rs
2025-05-17 12:23:37 +03:00

78 lines
No EOL
2.8 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

use azalea::{
prelude::*,
GameProfileComponent,
entity::{metadata::Player, Position},
pathfinder::goals::BlockPosGoal,
ecs::query::With,
};
pub async fn execute(
bot: Client,
sender: String,
mut command: String,
args: Vec<String>,
) -> anyhow::Result<bool> {
if command.starts_with('!') {
command.remove(0);
}
command = command.to_lowercase();
match command.as_str() {
"help" => {
send_command(bot, &format!("msg {sender} Доступные комманды: !help - Помощь, !tp - телепорт к Вам, !walk - подойдет к Вам (разрушая блоки), !say <text> - скажет, что Вы прикажете, !stop - завершит работу"));
Ok(true)
}
"stop" => {
info!("Stopping... Bye!");
std::process::exit(0);
}
"walk" => {
let sender_entity = bot.entity_by::<With<Player>, (&GameProfileComponent,)>(
|(profile,): &(&GameProfileComponent,)| profile.name == sender,
);
if let Some(sender_entity) = sender_entity {
let position = bot.entity_component::<Position>(sender_entity);
let goal = BlockPosGoal(azalea::BlockPos {
x: position.x.floor() as i32,
y: position.y.floor() as i32,
z: position.z.floor() as i32,
});
send_command(
bot.clone(),
&format!("msg {sender} Бегу к тебе!"),
);
// bot.goto_without_mining(goal).await;
bot.goto(goal).await;
} else {
send_command(
bot,
&format!("msg {sender} Не могу найти тебя! Возможно ты не в радиусе моей прогрузки :("),
);
}
Ok(true)
}
"tp" => {
info!("Teleporting to: {sender}");
send_command(bot, &format!("tpa {sender}"));
Ok(true)
}
"say" => {
let command_or_chat = args.join(" ");
if command_or_chat.starts_with("/") {
info!("Sending command: {command_or_chat}");
bot.send_command_packet(&format!("{}", &command_or_chat[1..]));
} else {
info!("Sending chat message: {command_or_chat}");
bot.send_chat_packet(&command_or_chat);
}
Ok(true)
}
_ => Ok(false),
}
}
pub fn send_command(bot: Client, command: &str) {
info!("Sending command: {command}");
bot.send_command_packet(command);
}