mirror of
https://github.com/TheFunny/TelegramTwitterMediaBot.git
synced 2026-10-05 01:12:06 +00:00
refactor(send): call send_animation directly
send_animation_inner only reshuffled its arguments into MediaSender's send_animation; both call sites (URL send and the reupload fallback) now call the sender themselves, which also drops the InputFile and MediaSender imports.
This commit is contained in:
@@ -14,14 +14,13 @@ mod upload;
|
|||||||
use crate::ctx::AppContext;
|
use crate::ctx::AppContext;
|
||||||
use crate::handlers::log_key;
|
use crate::handlers::log_key;
|
||||||
use crate::link_cache::{CachedMedia, CachedMediaKind, CachedPost};
|
use crate::link_cache::{CachedMedia, CachedMediaKind, CachedPost};
|
||||||
use crate::media_sender::MediaSender;
|
|
||||||
use input_media::{build_media_group, input_file_for, item_url};
|
use input_media::{build_media_group, input_file_for, item_url};
|
||||||
use post_send::{cache_animation_send, cache_sent_task};
|
use post_send::{cache_animation_send, cache_sent_task};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::sync::LazyLock;
|
use std::sync::LazyLock;
|
||||||
use teloxide::prelude::*;
|
use teloxide::prelude::*;
|
||||||
use teloxide::types::{ChatId, InputFile, InputMedia, MessageId};
|
use teloxide::types::{ChatId, InputMedia, MessageId};
|
||||||
use teloxide::{ApiError, RequestError};
|
use teloxide::{ApiError, RequestError};
|
||||||
use upload::{FallbackError, PreparedItem, prepare_upload_item, send_batch_via_upload};
|
use upload::{FallbackError, PreparedItem, prepare_upload_item, send_batch_via_upload};
|
||||||
|
|
||||||
@@ -683,25 +682,6 @@ pub async fn send_media_sequence(ctx: &AppContext<'_>, task: &Task) -> Result<Ve
|
|||||||
Ok(sent)
|
Ok(sent)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn send_animation_inner(
|
|
||||||
sender: &dyn MediaSender,
|
|
||||||
chat_id: i64,
|
|
||||||
reply_to: i64,
|
|
||||||
caption: &str,
|
|
||||||
spoiler: bool,
|
|
||||||
file: InputFile,
|
|
||||||
) -> Result<Message, RequestError> {
|
|
||||||
sender
|
|
||||||
.send_animation(
|
|
||||||
ChatId(chat_id),
|
|
||||||
MessageId(reply_to as i32),
|
|
||||||
caption,
|
|
||||||
spoiler,
|
|
||||||
file,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sends a lone animation (gif), URL first with the download fallback.
|
/// Sends a lone animation (gif), URL first with the download fallback.
|
||||||
pub async fn send_animation(ctx: &AppContext<'_>, task: &Task) -> Result<Vec<i64>, SendError> {
|
pub async fn send_animation(ctx: &AppContext<'_>, task: &Task) -> Result<Vec<i64>, SendError> {
|
||||||
let Task::SendAnimation {
|
let Task::SendAnimation {
|
||||||
@@ -737,10 +717,11 @@ pub async fn send_animation(ctx: &AppContext<'_>, task: &Task) -> Result<Vec<i64
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
match send_animation_inner(
|
match ctx
|
||||||
ctx.sender,
|
.sender
|
||||||
chat_id,
|
.send_animation(
|
||||||
reply_to,
|
ChatId(chat_id),
|
||||||
|
MessageId(reply_to as i32),
|
||||||
&caption,
|
&caption,
|
||||||
has_spoiler,
|
has_spoiler,
|
||||||
url_file,
|
url_file,
|
||||||
@@ -772,10 +753,11 @@ pub async fn send_animation(ctx: &AppContext<'_>, task: &Task) -> Result<Vec<i64
|
|||||||
};
|
};
|
||||||
// Hold the temp file until the request completes.
|
// Hold the temp file until the request completes.
|
||||||
let _keep_alive = keep_alive;
|
let _keep_alive = keep_alive;
|
||||||
match send_animation_inner(
|
match ctx
|
||||||
ctx.sender,
|
.sender
|
||||||
chat_id,
|
.send_animation(
|
||||||
reply_to,
|
ChatId(chat_id),
|
||||||
|
MessageId(reply_to as i32),
|
||||||
&caption,
|
&caption,
|
||||||
has_spoiler,
|
has_spoiler,
|
||||||
animation.media,
|
animation.media,
|
||||||
|
|||||||
Reference in New Issue
Block a user