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/tools.rs
2025-05-17 07:41:02 +03:00

46 lines
1.6 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 std::io;
use std::io::Write;
use azalea::prelude::*;
#[derive(Debug)]
pub struct BotAccount {
pub name_or_email: String,
pub account: Account
}
pub fn parse_nickname(data: &str) -> Option<&str> {
let start_index = data.find(']');
let end_index = data.find(':');
match (start_index, end_index) {
(Some(start), Some(end)) if start < end => {
Some(&data[start + 1..end].trim())
}
_ => {
None
}
}
}
pub async fn get_bot_account() -> BotAccount {
print!("Введите ник или Microsoft почту: ");
io::stdout().flush().expect("Не удалось очистить буфер вывода");
let mut name_or_email = String::new();
io::stdin().read_line(&mut name_or_email).expect("Не удалось прочитать строку");
if name_or_email.contains('@') {
return BotAccount { name_or_email: name_or_email.clone(), account: Account::microsoft(name_or_email.as_str()).await.unwrap() }
} else {
return BotAccount { name_or_email: name_or_email.clone(), account: Account::offline(name_or_email.as_str()) }
};
}
pub async fn get_owner_name() -> String {
print!("Введите СВОЙ ник в Minecraft (не ник бота): ");
io::stdout().flush().expect("Не удалось очистить буфер вывода");
let mut owner_name = String::new();
io::stdin().read_line(&mut owner_name).expect("Не удалось прочитать строку");
return owner_name;
}