no mark as spoiler corrupted images
This commit is contained in:
parent
ea565b8633
commit
dcf0623c4b
@ -10,8 +10,8 @@ use image::{DynamicImage,GenericImageView};
|
|||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
use tokio::io::BufStream;
|
use tokio::io::BufStream;
|
||||||
|
|
||||||
const TOLERANCE: i16 = 10;
|
const TOLERANCE: i16 = 0;
|
||||||
const PERCENT_ACEPTANCE: u8 = 15;
|
const PERCENT_ACEPTANCE: u8 = 5;
|
||||||
|
|
||||||
fn check_percent(img: DynamicImage) -> u8 {
|
fn check_percent(img: DynamicImage) -> u8 {
|
||||||
let mut cont = 0;
|
let mut cont = 0;
|
||||||
@ -64,6 +64,7 @@ pub async fn check_image(msg: Message, bot: Bot) -> anyhow::Result<()> {
|
|||||||
Some(s) => {
|
Some(s) => {
|
||||||
let mut percent = 0;
|
let mut percent = 0;
|
||||||
let mut id : Option<(String, u32)> = None;
|
let mut id : Option<(String, u32)> = None;
|
||||||
|
let mut failed = true;
|
||||||
for p in s {
|
for p in s {
|
||||||
let file = bot.get_file(p.file.id.clone()).await?;
|
let file = bot.get_file(p.file.id.clone()).await?;
|
||||||
let empty_memory: Vec<u8> = Vec::new();
|
let empty_memory: Vec<u8> = Vec::new();
|
||||||
@ -73,6 +74,7 @@ pub async fn check_image(msg: Message, bot: Bot) -> anyhow::Result<()> {
|
|||||||
let raw = reader.into_inner().into_inner().leak();
|
let raw = reader.into_inner().into_inner().leak();
|
||||||
match image::load_from_memory(raw) {
|
match image::load_from_memory(raw) {
|
||||||
Ok(img) => {
|
Ok(img) => {
|
||||||
|
failed = false;
|
||||||
let img_percent = check_percent(img);
|
let img_percent = check_percent(img);
|
||||||
if img_percent >= percent {
|
if img_percent >= percent {
|
||||||
percent = img_percent;
|
percent = img_percent;
|
||||||
@ -91,7 +93,7 @@ pub async fn check_image(msg: Message, bot: Bot) -> anyhow::Result<()> {
|
|||||||
Err(_e) => continue,
|
Err(_e) => continue,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if percent < PERCENT_ACEPTANCE {
|
if !failed && percent < PERCENT_ACEPTANCE {
|
||||||
bot.delete_message(msg.chat.id, msg.id).await?;
|
bot.delete_message(msg.chat.id, msg.id).await?;
|
||||||
let response = match id {
|
let response = match id {
|
||||||
Some(i) => bot.send_photo(msg.chat.id, teloxide::types::InputFile::file_id(i.0)).has_spoiler(true),
|
Some(i) => bot.send_photo(msg.chat.id, teloxide::types::InputFile::file_id(i.0)).has_spoiler(true),
|
||||||
|
Loading…
Reference in New Issue
Block a user