mirror of
https://github.com/shiroyashik/doggy-watch.git
synced 2025-12-06 04:21:13 +03:00
Add TELEGRAM_API_URL support, improve error handling in video metadata retrieval and fixing migration rollback
Some checks are pending
Docker Push / docker (push) Waiting to run
Some checks are pending
Docker Push / docker (push) Waiting to run
This commit is contained in:
parent
655e195c91
commit
fa125b47fb
7 changed files with 319 additions and 214 deletions
493
Cargo.lock
generated
493
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -26,6 +26,7 @@ tracing-panic = "0.1"
|
|||
lazy_static = "1.5"
|
||||
indexmap = "2.7"
|
||||
dashmap = "6.1"
|
||||
url = "2.5"
|
||||
|
||||
# https://github.com/teloxide/teloxide/issues/1154
|
||||
# [profile.dev]
|
||||
|
|
|
|||
|
|
@ -35,6 +35,10 @@ ID канала для проверки подписки.
|
|||
`trace, debug, info, warn, error`
|
||||
Также можно указать отдельный уровень логирования для отдельных целей.
|
||||
|
||||
`TELEGRAM_API_URL=<url>`
|
||||
|
||||
Сторонний Telegram Bot API сервер (необязательно).
|
||||
|
||||
### Только для Docker
|
||||
|
||||
`TZ=<TZ_identifier>`
|
||||
|
|
|
|||
|
|
@ -108,22 +108,22 @@ impl MigrationTrait for Migration {
|
|||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
// Videos
|
||||
// Actions
|
||||
manager
|
||||
.drop_table(Table::drop().table(Videos::Table).to_owned())
|
||||
.drop_table(Table::drop().table(Actions::Table).to_owned())
|
||||
.await?;
|
||||
// Requests
|
||||
manager
|
||||
.drop_table(Table::drop().table(Requests::Table).to_owned())
|
||||
.await?;
|
||||
// Actions
|
||||
manager
|
||||
.drop_table(Table::drop().table(Actions::Table).to_owned())
|
||||
.await?;
|
||||
// Archived
|
||||
manager
|
||||
.drop_table(Table::drop().table(Archived::Table).to_owned())
|
||||
.await?;
|
||||
// Videos
|
||||
manager
|
||||
.drop_table(Table::drop().table(Videos::Table).to_owned())
|
||||
.await?;
|
||||
// Moderators
|
||||
manager
|
||||
.drop_table(Table::drop().table(Moderators::Table).to_owned())
|
||||
|
|
|
|||
|
|
@ -13,7 +13,14 @@ pub async fn message(bot: Bot, msg: Message, dialogue: MyDialogue) -> anyhow::Re
|
|||
if let Some(user) = check_subscription(&bot, &msg.clone().from.ok_or(anyhow::anyhow!("Message not from user!"))?.id).await {
|
||||
// Get ready!
|
||||
if let Some(ytid) = extract_youtube_video_id(text) {
|
||||
let meta = get_video_metadata(&ytid).await?;
|
||||
let meta = match get_video_metadata(&ytid).await {
|
||||
Ok(meta) => meta,
|
||||
Err(err) => {
|
||||
tracing::error!("Caused an exception in get_video_metadata due: {err:?}");
|
||||
bot.send_message(msg.chat.id, "Ошибка при получении метаданных видео!").await?;
|
||||
return Ok(());
|
||||
},
|
||||
};
|
||||
// Post
|
||||
bot.send_message(msg.chat.id, format!(
|
||||
"Вы уверены что хотите добавить <b>{}</b>",
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ pub fn schema() -> UpdateHandler<anyhow::Error> {
|
|||
use dptree::case;
|
||||
let moderator_commands = dptree::entry()
|
||||
.branch(case![Command::Start].endpoint(start::command_mod))
|
||||
.branch(case![Command::Help].endpoint(start::command_mod))
|
||||
.branch(case![Command::List].endpoint(list::command))
|
||||
.branch(case![Command::Archive].endpoint(archive::command))
|
||||
.branch(case![Command::Mods].endpoint(moderator::list::command))
|
||||
|
|
|
|||
13
src/main.rs
13
src/main.rs
|
|
@ -17,6 +17,7 @@ mod markup;
|
|||
|
||||
mod inline;
|
||||
pub use inline::InlineCommand;
|
||||
use url::Url;
|
||||
|
||||
pub const COOLDOWN_DURATION: Duration = Duration::from_secs(10);
|
||||
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
|
|
@ -28,6 +29,12 @@ lazy_static! {
|
|||
pub static ref TOKEN: String = {
|
||||
var("TOKEN").expect("TOKEN env not set.")
|
||||
};
|
||||
pub static ref TELEGRAM_API_URL: Url = {
|
||||
match var("TELEGRAM_API_URL") {
|
||||
Ok(url) => url.parse().expect("Can't parse TELEGRAM_API_URL"),
|
||||
Err(_) => teloxide::net::TELEGRAM_API_URL.parse().expect("Failed to parse default Telegram bot API url")
|
||||
}
|
||||
};
|
||||
pub static ref DATABASE_URL: String = {
|
||||
var("DATABASE_URL").expect("DATABASE_URL env not set.")
|
||||
};
|
||||
|
|
@ -60,8 +67,8 @@ async fn main() -> anyhow::Result<()> {
|
|||
}));
|
||||
|
||||
tracing::info!("Doggy-Watch v{VERSION}");
|
||||
tracing::info!("{:?}", *ADMINISTRATORS);
|
||||
let bot = Bot::new(&*TOKEN);
|
||||
tracing::info!("admins: {:?} tg api: {}", *ADMINISTRATORS, TELEGRAM_API_URL.as_str());
|
||||
let bot = Bot::new(&*TOKEN).set_api_url(TELEGRAM_API_URL.clone());
|
||||
|
||||
let mut opt = ConnectOptions::new(&*DATABASE_URL);
|
||||
opt.sqlx_logging_level(tracing::log::LevelFilter::Trace);
|
||||
|
|
@ -120,6 +127,8 @@ pub enum DialogueState {
|
|||
enum Command {
|
||||
#[command(description = "запустить бота и/или вывести этот текст.")]
|
||||
Start,
|
||||
#[command(description = "вывести этот текст.")]
|
||||
Help,
|
||||
#[command(description = "вывести список.")]
|
||||
List,
|
||||
#[command(description = "действия с архивом.")]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue