Skip to content

Commit

Permalink
chore: use Sticker.format instead of the file extension
Browse files Browse the repository at this point in the history
  • Loading branch information
nanpuyue committed Mar 22, 2024
1 parent cf49803 commit 987ec9e
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{env, io};
use lazy_static::lazy_static;
use teloxide::net::Download;
use teloxide::prelude::*;
use teloxide::types::{InputFile, MessageEntity, MessageEntityKind};
use teloxide::types::{InputFile, MessageEntity, MessageEntityKind, StickerFormat::*};
use teloxide::utils::command::BotCommands;
use tokio::sync::Mutex;

Expand Down Expand Up @@ -87,19 +87,12 @@ impl Command {
let mut buf = Vec::new();
let file = bot.get_file(file_id).await?;

let mut file_ext = String::new();
if file_type == "sticker" {
if let Some((_, x)) = file.path.rsplit_once('.') {
file_ext = x.to_ascii_lowercase()
}
}

let tgs_to_png;
let mut download = true;
let mut file_to_png: Option<&(dyn Fn(_) -> _ + Sync)> = None;
match (file_type, file_ext.as_str()) {
("sticker", "webp") | ("photo", _) => {}
("sticker", "tgs") => {
match (file_type, message.sticker().map(|x| &x.format)) {
("sticker", Some(Raster)) | ("photo", _) => {}
("sticker", Some(Animated)) => {
tgs_to_png = |x| crate::image::tgs_to_png(x, file_id);
file_to_png.replace(&tgs_to_png);
}
Expand Down

0 comments on commit 987ec9e

Please sign in to comment.