mirror of
https://github.com/flibusta-apps/book_bot.git
synced 2025-12-06 15:35:35 +01:00
Handle AlreadyExists (409) during registration
This commit is contained in:
@@ -19,9 +19,10 @@ pub async fn message_handler(message: Message, bot: CacheMe<Throttle<Bot>>) -> a
|
||||
|
||||
let message_text = match result {
|
||||
register::RegisterStatus::Success { ref username } => format_registered_message(username),
|
||||
register::RegisterStatus::RegisterFail => strings::ALREADY_REGISTERED.to_string(),
|
||||
register::RegisterStatus::RegisterFail => strings::MAY_BE_ALREADY_REGISTERED.to_string(),
|
||||
register::RegisterStatus::LimitExtended => strings::LIMIT_EXTENDED_MESSAGE.to_string(),
|
||||
register::RegisterStatus::WrongToken => strings::ERROR_MESSAGE.to_string(),
|
||||
register::RegisterStatus::AlreadyExists => strings::ALREADY_EXISTS_MESSAGE.to_string(),
|
||||
};
|
||||
|
||||
bot.send_message(message.chat.id, message_text)
|
||||
|
||||
@@ -12,12 +12,14 @@ pub enum RegisterStatus {
|
||||
WrongToken,
|
||||
RegisterFail,
|
||||
LimitExtended,
|
||||
AlreadyExists,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum RegisterRequestStatus {
|
||||
Success,
|
||||
LimitExtended,
|
||||
AlreadyExists,
|
||||
UnknownError,
|
||||
}
|
||||
|
||||
@@ -52,6 +54,7 @@ async fn make_register_request(
|
||||
Ok(match result.status().as_u16() {
|
||||
200 => RegisterRequestStatus::Success,
|
||||
402 => RegisterRequestStatus::LimitExtended,
|
||||
409 => RegisterRequestStatus::AlreadyExists,
|
||||
_ => RegisterRequestStatus::UnknownError,
|
||||
})
|
||||
}
|
||||
@@ -81,5 +84,6 @@ pub async fn register(user_id: UserId, message_text: &str) -> RegisterStatus {
|
||||
},
|
||||
RegisterRequestStatus::LimitExtended => RegisterStatus::LimitExtended,
|
||||
RegisterRequestStatus::UnknownError => RegisterStatus::RegisterFail,
|
||||
RegisterRequestStatus::AlreadyExists => RegisterStatus::AlreadyExists,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,10 @@ pub fn format_registered_message(username: &str) -> String {
|
||||
format!("@{username} зарегистрирован и через несколько минут будет подключен!")
|
||||
}
|
||||
|
||||
pub const ALREADY_REGISTERED: &str = "Ошибка! Возможно бот уже зарегистрирован!";
|
||||
pub const MAY_BE_ALREADY_REGISTERED: &str = "Ошибка! Возможно бот уже зарегистрирован!";
|
||||
|
||||
pub const ERROR_MESSAGE: &str = "Ошибка! Что-то не так с ботом!";
|
||||
|
||||
pub const LIMIT_EXTENDED_MESSAGE: &str = "Вы достигли максимального количества ботов!";
|
||||
|
||||
pub const ALREADY_EXISTS_MESSAGE: &str = "Ошибка! Бот с таким токеном уже зарегистрирован!";
|
||||
|
||||
Reference in New Issue
Block a user