46 lines
1.6 KiB
Rust
46 lines
1.6 KiB
Rust
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;
|
||
}
|