use super::CommandExecutor;
use crate::client::result::CommandResult;
impl CommandExecutor {
pub async fn pair_confirm(&self, code: &str, chat_id: i64) -> CommandResult {
match self.client().pair_confirm(code, chat_id).await {
Ok(confirm) if confirm.success => CommandResult::PairSuccess {
chat_info: format!("chat {}", confirm.chat_id.unwrap_or(chat_id)),
},
Ok(confirm) => CommandResult::Error(
confirm
.error
.unwrap_or_else(|| "invalid or expired code".to_string()),
),
Err(e) => CommandResult::Error(format!("daemon unreachable: {e}")),
}
}
pub async fn pair_request(&self) -> CommandResult {
match self.client().pair_request().await {
Ok(req) => CommandResult::PairCode {
code: req.code,
expires_in_seconds: req.expires_in_seconds,
},
Err(e) => CommandResult::Error(format!("daemon unreachable: {e}")),
}
}
pub(super) async fn pair_state(&self) -> CommandResult {
match self.client().pair_status().await {
Ok(status) => CommandResult::PairState {
paired: status.paired,
},
Err(e) => CommandResult::Error(format!("daemon unreachable: {e}")),
}
}
}