mirror of
https://github.com/flibusta-apps/book_bot.git
synced 2025-12-06 07:25:36 +01:00
Update teloxide
This commit is contained in:
@@ -73,7 +73,7 @@ fn update_user_activity_handler() -> BotHandler {
|
||||
)
|
||||
.branch(Update::filter_message().chain(dptree::filter_map_async(
|
||||
|message: Message, bot: CacheMe<Throttle<Bot>>| async move {
|
||||
match message.from() {
|
||||
match message.from {
|
||||
Some(user) => _update_activity(bot.get_me().await.unwrap(), user.clone()).await,
|
||||
None => None,
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ where
|
||||
if annotation.get_file().is_none() && !annotation.is_normal_text() {
|
||||
return match bot
|
||||
.send_message(message.chat.id, "Аннотация недоступна :(")
|
||||
.reply_to_message_id(message.id)
|
||||
.reply_parameters(ReplyParameters::new(message.id))
|
||||
.send()
|
||||
.await
|
||||
{
|
||||
@@ -149,7 +149,7 @@ where
|
||||
let keyboard =
|
||||
generic_get_pagination_keyboard(page, chunked_text.len().try_into()?, callback_data, false);
|
||||
|
||||
bot.edit_message_text(message.chat.id, message.id, current_text)
|
||||
bot.edit_message_text(message.chat().id, message.id(), current_text)
|
||||
.reply_markup(keyboard)
|
||||
.send()
|
||||
.await?;
|
||||
|
||||
@@ -48,7 +48,7 @@ where
|
||||
};
|
||||
|
||||
let chat_id = message.chat.id;
|
||||
let user_id = message.from().map(|from| from.id);
|
||||
let user_id = message.from.map(|from| from.id);
|
||||
|
||||
let user_id = match user_id {
|
||||
Some(v) => v,
|
||||
@@ -118,9 +118,9 @@ where
|
||||
BookCallbackData::Sequence { id, page } => (id, page),
|
||||
};
|
||||
|
||||
let chat_id = cq.message.as_ref().map(|message| message.chat.id);
|
||||
let chat_id = cq.message.as_ref().map(|message| message.chat().id);
|
||||
let user_id = cq.from.id;
|
||||
let message_id = cq.message.as_ref().map(|message| message.id);
|
||||
let message_id = cq.message.as_ref().map(|message| message.id());
|
||||
|
||||
let (chat_id, message_id) = match (chat_id, message_id) {
|
||||
(Some(chat_id), Some(message_id)) => (chat_id, message_id),
|
||||
|
||||
@@ -60,13 +60,13 @@ fn get_check_keyboard(task_id: String) -> InlineKeyboardMarkup {
|
||||
}
|
||||
|
||||
async fn _send_cached(
|
||||
message: &Message,
|
||||
message: &MaybeInaccessibleMessage,
|
||||
bot: &CacheMe<Throttle<Bot>>,
|
||||
cached_message: CachedMessage,
|
||||
) -> BotHandlerInternal {
|
||||
match bot
|
||||
.copy_message(
|
||||
message.chat.id,
|
||||
message.chat().id,
|
||||
Recipient::Id(ChatId(cached_message.chat_id)),
|
||||
MessageId(cached_message.message_id),
|
||||
)
|
||||
@@ -79,7 +79,7 @@ async fn _send_cached(
|
||||
}
|
||||
|
||||
async fn send_cached_message(
|
||||
message: Message,
|
||||
message: MaybeInaccessibleMessage,
|
||||
bot: CacheMe<Throttle<Bot>>,
|
||||
download_data: DownloadQueryData,
|
||||
need_delete_message: bool,
|
||||
@@ -94,7 +94,9 @@ async fn send_cached_message(
|
||||
|
||||
if _send_cached(&message, &bot, cached).await.is_ok() {
|
||||
if need_delete_message {
|
||||
bot.delete_message(message.chat.id, message.id).await?;
|
||||
if let MaybeInaccessibleMessage::Regular(message) = message.clone() {
|
||||
bot.delete_message(message.chat.id, message.id).await?;
|
||||
}
|
||||
}
|
||||
|
||||
match send_donation_notification(bot.clone(), message).await {
|
||||
@@ -113,7 +115,7 @@ async fn send_cached_message(
|
||||
}
|
||||
|
||||
async fn _send_downloaded_file(
|
||||
message: &Message,
|
||||
message: &MaybeInaccessibleMessage,
|
||||
bot: CacheMe<Throttle<Bot>>,
|
||||
downloaded_data: DownloadFile,
|
||||
) -> BotHandlerInternal {
|
||||
@@ -131,7 +133,7 @@ async fn _send_downloaded_file(
|
||||
|
||||
let document: InputFile = InputFile::read(data).file_name(filename.clone());
|
||||
|
||||
match bot.send_document(message.chat.id, document)
|
||||
match bot.send_document(message.chat().id, document)
|
||||
.caption(caption)
|
||||
.send()
|
||||
.await {
|
||||
@@ -152,7 +154,7 @@ async fn _send_downloaded_file(
|
||||
|
||||
|
||||
async fn send_with_download_from_channel(
|
||||
message: Message,
|
||||
message: MaybeInaccessibleMessage,
|
||||
bot: CacheMe<Throttle<Bot>>,
|
||||
download_data: DownloadQueryData,
|
||||
need_delete_message: bool,
|
||||
@@ -169,7 +171,9 @@ async fn send_with_download_from_channel(
|
||||
_send_downloaded_file(&message, bot.clone(), download_file).await?;
|
||||
|
||||
if need_delete_message {
|
||||
bot.delete_message(message.chat.id, message.id).await?;
|
||||
if let MaybeInaccessibleMessage::Regular(message) = message {
|
||||
bot.delete_message(message.chat.id, message.id).await?;
|
||||
};
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -180,7 +184,7 @@ async fn send_with_download_from_channel(
|
||||
|
||||
|
||||
async fn download_handler(
|
||||
message: Message,
|
||||
message: MaybeInaccessibleMessage,
|
||||
bot: CacheMe<Throttle<Bot>>,
|
||||
cache: BotCache,
|
||||
download_data: DownloadQueryData,
|
||||
@@ -233,7 +237,7 @@ async fn get_download_keyboard_handler(
|
||||
|
||||
bot.send_message(message.chat.id, "Выбери формат:")
|
||||
.reply_markup(keyboard)
|
||||
.reply_to_message_id(message.id)
|
||||
.reply_parameters(ReplyParameters::new(message.id))
|
||||
.send()
|
||||
.await?;
|
||||
|
||||
@@ -245,7 +249,7 @@ async fn get_download_archive_keyboard_handler(
|
||||
bot: CacheMe<Throttle<Bot>>,
|
||||
command: DownloadArchiveCommand,
|
||||
) -> BotHandlerInternal {
|
||||
let allowed_langs = get_user_or_default_lang_codes(message.from().unwrap().id).await;
|
||||
let allowed_langs = get_user_or_default_lang_codes(message.from.unwrap().id).await;
|
||||
|
||||
let available_types = match command {
|
||||
DownloadArchiveCommand::Sequence { id } => {
|
||||
@@ -299,7 +303,7 @@ async fn get_download_archive_keyboard_handler(
|
||||
|
||||
bot.send_message(message.chat.id, "Выбери формат:")
|
||||
.reply_markup(keyboard)
|
||||
.reply_to_message_id(message.id)
|
||||
.reply_parameters(ReplyParameters::new(message.id))
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
@@ -347,10 +351,18 @@ async fn send_archive_link(
|
||||
async fn wait_archive(
|
||||
bot: CacheMe<Throttle<Bot>>,
|
||||
task_id: String,
|
||||
message: Message,
|
||||
input_message: MaybeInaccessibleMessage,
|
||||
) -> BotHandlerInternal {
|
||||
let mut interval = time::interval(Duration::from_secs(15));
|
||||
|
||||
let message = match input_message {
|
||||
MaybeInaccessibleMessage::Regular(message) => message,
|
||||
_ => {
|
||||
send_error_message(bot, input_message.chat().id, input_message.id()).await;
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
|
||||
let task = loop {
|
||||
interval.tick().await;
|
||||
|
||||
@@ -420,7 +432,7 @@ async fn wait_archive(
|
||||
}
|
||||
};
|
||||
|
||||
match _send_downloaded_file(&message, bot.clone(), downloaded_data).await {
|
||||
match _send_downloaded_file(&MaybeInaccessibleMessage::Regular(message.clone()), bot.clone(), downloaded_data).await {
|
||||
Ok(_) => (),
|
||||
Err(err) => {
|
||||
send_archive_link(bot.clone(), message.clone(), task).await?;
|
||||
@@ -465,13 +477,13 @@ async fn download_archive(
|
||||
let task = match task {
|
||||
Ok(v) => v,
|
||||
Err(err) => {
|
||||
send_error_message(bot, message.chat.id, message.id).await;
|
||||
send_error_message(bot, message.chat().id, message.id()).await;
|
||||
log::error!("{:?}", err);
|
||||
return Err(err);
|
||||
}
|
||||
};
|
||||
|
||||
bot.edit_message_text(message.chat.id, message.id, "⏳ Подготовка архива...")
|
||||
bot.edit_message_text(message.chat().id, message.id(), "⏳ Подготовка архива...")
|
||||
.reply_markup(get_check_keyboard(task.id.clone()))
|
||||
.send()
|
||||
.await?;
|
||||
|
||||
@@ -12,7 +12,7 @@ use self::commands::HelpCommand;
|
||||
|
||||
pub async fn help_handler(message: Message, bot: CacheMe<Throttle<Bot>>) -> BotHandlerInternal {
|
||||
let name = message
|
||||
.from()
|
||||
.from
|
||||
.map(|user| user.first_name.clone())
|
||||
.unwrap_or("пользователь".to_string());
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ use smartstring::alias::String as SmartString;
|
||||
use teloxide::{
|
||||
adaptors::{CacheMe, Throttle},
|
||||
prelude::*,
|
||||
types::{InlineKeyboardButton, InlineKeyboardMarkup},
|
||||
types::{InlineKeyboardButton, InlineKeyboardMarkup, ReplyParameters},
|
||||
};
|
||||
|
||||
use crate::bots::{
|
||||
@@ -59,7 +59,7 @@ async fn random_handler(
|
||||
};
|
||||
|
||||
bot.send_message(message.chat.id, MESSAGE_TEXT)
|
||||
.reply_to_message_id(message.id)
|
||||
.reply_parameters(ReplyParameters::new(message.id))
|
||||
.reply_markup(keyboard)
|
||||
.send()
|
||||
.await?;
|
||||
@@ -99,7 +99,7 @@ where
|
||||
|
||||
match cq.message {
|
||||
Some(message) => {
|
||||
bot.edit_message_reply_markup(message.chat.id, message.id)
|
||||
bot.edit_message_reply_markup(message.chat().id, message.id())
|
||||
.reply_markup(InlineKeyboardMarkup {
|
||||
inline_keyboard: vec![],
|
||||
})
|
||||
@@ -161,7 +161,7 @@ async fn get_genre_metas_handler(
|
||||
.collect(),
|
||||
};
|
||||
|
||||
bot.edit_message_reply_markup(message.chat.id, message.id)
|
||||
bot.edit_message_reply_markup(message.chat().id, message.id())
|
||||
.reply_markup(keyboard)
|
||||
.send()
|
||||
.await?;
|
||||
@@ -225,7 +225,7 @@ async fn get_genres_by_meta_handler(
|
||||
}
|
||||
};
|
||||
|
||||
bot.edit_message_reply_markup(message.chat.id, message.id)
|
||||
bot.edit_message_reply_markup(message.chat().id, message.id())
|
||||
.reply_markup(keyboard)
|
||||
.send()
|
||||
.await?;
|
||||
|
||||
@@ -9,7 +9,7 @@ use teloxide::{
|
||||
adaptors::{CacheMe, Throttle},
|
||||
dispatching::dialogue::GetChatId,
|
||||
prelude::*,
|
||||
types::{InlineKeyboardButton, InlineKeyboardMarkup},
|
||||
types::{InlineKeyboardButton, InlineKeyboardMarkup, ReplyParameters},
|
||||
};
|
||||
|
||||
use crate::bots::{
|
||||
@@ -44,7 +44,7 @@ where
|
||||
{
|
||||
let chat_id = cq.chat_id();
|
||||
let user_id = cq.from.id;
|
||||
let message_id = cq.message.as_ref().map(|message| message.id);
|
||||
let message_id = cq.message.as_ref().map(|message| message.id());
|
||||
let query = get_query(cq);
|
||||
|
||||
let (chat_id, query, message_id) = match (chat_id, query, message_id) {
|
||||
@@ -151,7 +151,7 @@ pub async fn message_handler(message: Message, bot: CacheMe<Throttle<Bot>>) -> B
|
||||
};
|
||||
|
||||
bot.send_message(message.chat.id, message_text)
|
||||
.reply_to_message_id(message.id)
|
||||
.reply_parameters(ReplyParameters::new(message.id))
|
||||
.reply_markup(keyboard)
|
||||
.send()
|
||||
.await?;
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
use teloxide::types::CallbackQuery;
|
||||
use teloxide::types::{CallbackQuery, MaybeInaccessibleMessage};
|
||||
|
||||
|
||||
pub fn get_query(cq: CallbackQuery) -> Option<String> {
|
||||
cq.message
|
||||
.map(|message| {
|
||||
message
|
||||
.reply_to_message()
|
||||
.map(|reply_to_message| {
|
||||
reply_to_message
|
||||
match cq.message {
|
||||
Some(message) => {
|
||||
match message {
|
||||
MaybeInaccessibleMessage::Regular(message) => {
|
||||
message
|
||||
.text()
|
||||
.map(|text| text.replace(['/', '&', '?'], ""))
|
||||
})
|
||||
.unwrap_or(None)
|
||||
})
|
||||
.unwrap_or(None)
|
||||
.map_or(None, |text| Some(text.replace(['/', '&', '?'], "")))
|
||||
}
|
||||
MaybeInaccessibleMessage::Inaccessible(_) => None,
|
||||
}
|
||||
}
|
||||
None => None,
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ async fn settings_callback_handler(
|
||||
)
|
||||
.await
|
||||
{
|
||||
bot.send_message(message.chat.id, "Ошибка! Попробуйте заново(")
|
||||
bot.send_message(message.chat().id, "Ошибка! Попробуйте заново(")
|
||||
.send()
|
||||
.await?;
|
||||
return Err(err);
|
||||
@@ -135,7 +135,7 @@ async fn settings_callback_handler(
|
||||
let all_langs = match get_langs().await {
|
||||
Ok(v) => v,
|
||||
Err(err) => {
|
||||
bot.send_message(message.chat.id, "Ошибка! Попробуйте заново(")
|
||||
bot.send_message(message.chat().id, "Ошибка! Попробуйте заново(")
|
||||
.send()
|
||||
.await?;
|
||||
return Err(err);
|
||||
@@ -144,7 +144,7 @@ async fn settings_callback_handler(
|
||||
|
||||
let keyboard = get_lang_keyboard(all_langs, allowed_langs_set);
|
||||
|
||||
bot.edit_message_reply_markup(message.chat.id, message.id)
|
||||
bot.edit_message_reply_markup(message.chat().id, message.id())
|
||||
.reply_markup(keyboard)
|
||||
.send()
|
||||
.await?;
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
use crate::bots::BotHandlerInternal;
|
||||
|
||||
use teloxide::{
|
||||
adaptors::{CacheMe, Throttle},
|
||||
prelude::*,
|
||||
utils::command::BotCommands,
|
||||
adaptors::{CacheMe, Throttle}, prelude::*, types::MaybeInaccessibleMessage, utils::command::BotCommands
|
||||
};
|
||||
|
||||
#[derive(BotCommands, Clone)]
|
||||
@@ -14,20 +12,28 @@ enum SupportCommand {
|
||||
}
|
||||
|
||||
pub async fn support_command_handler(
|
||||
message: Message,
|
||||
orgingal_message: MaybeInaccessibleMessage,
|
||||
bot: CacheMe<Throttle<Bot>>,
|
||||
) -> BotHandlerInternal {
|
||||
let is_bot = message.from().unwrap().is_bot;
|
||||
let message = match orgingal_message {
|
||||
MaybeInaccessibleMessage::Regular(message) => message,
|
||||
MaybeInaccessibleMessage::Inaccessible(_) => return Ok(()),
|
||||
};
|
||||
|
||||
let username = if is_bot {
|
||||
&message
|
||||
.reply_to_message()
|
||||
.unwrap()
|
||||
.from()
|
||||
.unwrap()
|
||||
.first_name
|
||||
} else {
|
||||
&message.from().unwrap().first_name
|
||||
let username = match message.clone().from {
|
||||
Some(user) => {
|
||||
match user.is_bot {
|
||||
true => match message.reply_to_message() {
|
||||
Some(v) => match &v.from {
|
||||
Some(v) => v.first_name.clone(),
|
||||
None => "пользователь".to_string(),
|
||||
},
|
||||
None => "пользователь".to_string(),
|
||||
},
|
||||
false => user.first_name,
|
||||
}
|
||||
}
|
||||
None => "пользователь".to_string(),
|
||||
};
|
||||
|
||||
let message_text = format!(
|
||||
@@ -59,7 +65,6 @@ The Open Network - TON:
|
||||
|
||||
bot.send_message(message.chat.id, message_text)
|
||||
.parse_mode(teloxide::types::ParseMode::Html)
|
||||
.disable_web_page_preview(true)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -109,7 +109,7 @@ async fn update_log_pagination_handler(
|
||||
.await?;
|
||||
|
||||
if items_page.pages == 0 {
|
||||
bot.send_message(message.chat.id, "Нет новых книг за этот период.")
|
||||
bot.send_message(message.chat().id, "Нет новых книг за этот период.")
|
||||
.send()
|
||||
.await?;
|
||||
return Ok(());
|
||||
@@ -140,7 +140,7 @@ async fn update_log_pagination_handler(
|
||||
let message_text = format!("{header}{formatted_page}");
|
||||
|
||||
let keyboard = generic_get_pagination_keyboard(page, total_pages, update_callback_data, true);
|
||||
bot.edit_message_text(message.chat.id, message.id, message_text)
|
||||
bot.edit_message_text(message.chat().id, message.id(), message_text)
|
||||
.reply_markup(keyboard)
|
||||
.send()
|
||||
.await?;
|
||||
|
||||
@@ -40,7 +40,7 @@ pub struct Task {
|
||||
pub id: String,
|
||||
pub status: TaskStatus,
|
||||
pub status_description: String,
|
||||
pub error_message: Option<String>,
|
||||
// pub error_message: Option<String>,
|
||||
pub result_filename: Option<String>,
|
||||
pub content_size: Option<u64>,
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ pub struct BookTranslator {
|
||||
|
||||
#[derive(Deserialize, Debug, Clone)]
|
||||
pub struct BookGenre {
|
||||
pub id: u32,
|
||||
// pub id: u32,
|
||||
pub description: String,
|
||||
}
|
||||
|
||||
@@ -65,11 +65,11 @@ pub struct Sequence {
|
||||
#[derive(Deserialize, Debug, Clone)]
|
||||
pub struct Genre {
|
||||
pub id: u32,
|
||||
pub source: Source,
|
||||
pub remote_id: u32,
|
||||
pub code: String,
|
||||
// pub source: Source,
|
||||
// pub remote_id: u32,
|
||||
// pub code: String,
|
||||
pub description: String,
|
||||
pub meta: String,
|
||||
// pub meta: String,
|
||||
}
|
||||
|
||||
#[derive(Default, Deserialize, Debug, Clone)]
|
||||
@@ -78,11 +78,11 @@ pub struct Empty {}
|
||||
#[derive(Deserialize, Debug, Clone)]
|
||||
pub struct Page<T, P> {
|
||||
pub items: Vec<T>,
|
||||
pub total: u32,
|
||||
// pub total: u32,
|
||||
|
||||
pub page: u32,
|
||||
// pub page: u32,
|
||||
|
||||
pub size: u32,
|
||||
// pub size: u32,
|
||||
pub pages: u32,
|
||||
|
||||
#[serde(default)]
|
||||
@@ -173,16 +173,16 @@ where
|
||||
|
||||
#[derive(Deserialize, Debug, Clone)]
|
||||
pub struct BookAnnotation {
|
||||
pub id: u32,
|
||||
pub title: String,
|
||||
// pub id: u32,
|
||||
// pub title: String,
|
||||
pub text: String,
|
||||
pub file: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug, Clone)]
|
||||
pub struct AuthorAnnotation {
|
||||
pub id: u32,
|
||||
pub title: String,
|
||||
// pub id: u32,
|
||||
// pub title: String,
|
||||
pub text: String,
|
||||
pub file: Option<String>,
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
use teloxide::{
|
||||
adaptors::{CacheMe, Throttle},
|
||||
types::Message,
|
||||
Bot,
|
||||
adaptors::{CacheMe, Throttle}, types::MaybeInaccessibleMessage, Bot
|
||||
};
|
||||
|
||||
use crate::{
|
||||
@@ -13,25 +11,25 @@ use super::user_settings::{is_need_donate_notifications, mark_donate_notificatio
|
||||
|
||||
pub async fn send_donation_notification(
|
||||
bot: CacheMe<Throttle<Bot>>,
|
||||
message: Message,
|
||||
message: MaybeInaccessibleMessage,
|
||||
) -> BotHandlerInternal {
|
||||
if CHAT_DONATION_NOTIFICATIONS_CACHE
|
||||
.get(&message.chat.id)
|
||||
.get(&message.chat().id)
|
||||
.await
|
||||
.is_some()
|
||||
{
|
||||
return Ok(());
|
||||
} else if !is_need_donate_notifications(message.chat.id, message.chat.is_private()).await? {
|
||||
} else if !is_need_donate_notifications(message.chat().id, message.chat().is_private()).await? {
|
||||
CHAT_DONATION_NOTIFICATIONS_CACHE
|
||||
.insert(message.chat.id, ())
|
||||
.insert(message.chat().id, ())
|
||||
.await;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
CHAT_DONATION_NOTIFICATIONS_CACHE
|
||||
.insert(message.chat.id, ())
|
||||
.insert(message.chat().id, ())
|
||||
.await;
|
||||
mark_donate_notification_sent(message.chat.id).await?;
|
||||
mark_donate_notification_sent(message.chat().id).await?;
|
||||
|
||||
support_command_handler(message, bot).await?;
|
||||
|
||||
|
||||
@@ -22,11 +22,11 @@ pub struct Lang {
|
||||
|
||||
#[derive(Deserialize, Debug, Clone)]
|
||||
pub struct UserSettings {
|
||||
pub user_id: u64,
|
||||
pub last_name: SmartString,
|
||||
pub first_name: SmartString,
|
||||
pub username: SmartString,
|
||||
pub source: SmartString,
|
||||
// pub user_id: u64,
|
||||
// pub last_name: SmartString,
|
||||
// pub first_name: SmartString,
|
||||
// pub username: SmartString,
|
||||
// pub source: SmartString,
|
||||
pub allowed_langs: SmallVec<[Lang; 3]>,
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use teloxide::{
|
||||
adaptors::{CacheMe, Throttle},
|
||||
prelude::*,
|
||||
prelude::*, types::ReplyParameters,
|
||||
};
|
||||
|
||||
use std::error::Error;
|
||||
@@ -16,7 +16,7 @@ pub async fn message_handler(
|
||||
message: Message,
|
||||
bot: CacheMe<Throttle<Bot>>,
|
||||
) -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||
let from_user = message.from().unwrap();
|
||||
let from_user = message.clone().from.unwrap();
|
||||
let text = message.text().unwrap_or("");
|
||||
|
||||
let result = register::register(from_user.id, text).await;
|
||||
@@ -29,7 +29,7 @@ pub async fn message_handler(
|
||||
};
|
||||
|
||||
bot.send_message(message.chat.id, message_text)
|
||||
.reply_to_message_id(message.id)
|
||||
.reply_parameters(ReplyParameters::new(message.id))
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -18,7 +18,7 @@ pub enum RegisterStatus {
|
||||
pub enum RegisterRequestStatus {
|
||||
Success,
|
||||
LimitExtended,
|
||||
UnknownError { status_code: u16 },
|
||||
UnknownError,
|
||||
}
|
||||
|
||||
async fn get_bot_username(token: &str) -> Option<String> {
|
||||
@@ -55,7 +55,7 @@ async fn make_register_request(
|
||||
Ok(match result.status().as_u16() {
|
||||
200 => RegisterRequestStatus::Success,
|
||||
402 => RegisterRequestStatus::LimitExtended,
|
||||
status_code => RegisterRequestStatus::UnknownError { status_code },
|
||||
_ => RegisterRequestStatus::UnknownError,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ use url::Url;
|
||||
|
||||
use std::convert::Infallible;
|
||||
|
||||
use crate::bots_manager::bot_manager_client::delete_bot;
|
||||
use crate::bots_manager::BOTS_ROUTES;
|
||||
use crate::config;
|
||||
|
||||
@@ -65,10 +64,10 @@ pub async fn set_webhook(bot_data: &BotData) -> bool {
|
||||
match bot.set_webhook(url.clone()).await {
|
||||
Ok(_) => true,
|
||||
Err(err) => {
|
||||
if let teloxide::RequestError::Api(ref err) = err {
|
||||
if err == &teloxide::ApiError::NotFound {
|
||||
let _ = delete_bot(bot_data.id).await;
|
||||
}
|
||||
if let teloxide::RequestError::Api(ref _err) = err {
|
||||
// if err == &teloxide::ApiError::NotFound {
|
||||
// let _ = delete_bot(bot_data.id).await;
|
||||
// }
|
||||
}
|
||||
|
||||
log::error!("Webhook set error: {}", err);
|
||||
|
||||
@@ -6,8 +6,8 @@ pub struct Config {
|
||||
pub webhook_base_url: String,
|
||||
pub webhook_port: u16,
|
||||
|
||||
pub admin_id: String,
|
||||
pub bot_token: String,
|
||||
// pub admin_id: String,
|
||||
// pub bot_token: String,
|
||||
pub manager_url: String,
|
||||
pub manager_api_key: String,
|
||||
|
||||
@@ -42,8 +42,8 @@ impl Config {
|
||||
webhook_base_url: get_env("WEBHOOK_BASE_URL"),
|
||||
webhook_port: get_env("WEBHOOK_PORT").parse().unwrap(),
|
||||
|
||||
admin_id: get_env("ADMIN_ID"),
|
||||
bot_token: get_env("BOT_TOKEN"),
|
||||
// admin_id: get_env("ADMIN_ID"),
|
||||
// bot_token: get_env("BOT_TOKEN"),
|
||||
manager_url: get_env("MANAGER_URL"),
|
||||
manager_api_key: get_env("MANAGER_API_KEY"),
|
||||
|
||||
|
||||
Reference in New Issue
Block a user