no mark as spoiler corrupted images

This commit is contained in:
Guillermo Roche 2023-11-12 19:34:44 +01:00
parent ea565b8633
commit dcf0623c4b
2 changed files with 5 additions and 3 deletions

BIN
data.db Normal file

Binary file not shown.

View File

@ -10,8 +10,8 @@ use image::{DynamicImage,GenericImageView};
use std::io::Cursor;
use tokio::io::BufStream;
const TOLERANCE: i16 = 10;
const PERCENT_ACEPTANCE: u8 = 15;
const TOLERANCE: i16 = 0;
const PERCENT_ACEPTANCE: u8 = 5;
fn check_percent(img: DynamicImage) -> u8 {
let mut cont = 0;
@ -64,6 +64,7 @@ pub async fn check_image(msg: Message, bot: Bot) -> anyhow::Result<()> {
Some(s) => {
let mut percent = 0;
let mut id : Option<(String, u32)> = None;
let mut failed = true;
for p in s {
let file = bot.get_file(p.file.id.clone()).await?;
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();
match image::load_from_memory(raw) {
Ok(img) => {
failed = false;
let img_percent = check_percent(img);
if img_percent >= percent {
percent = img_percent;
@ -91,7 +93,7 @@ pub async fn check_image(msg: Message, bot: Bot) -> anyhow::Result<()> {
Err(_e) => continue,
}
}
if percent < PERCENT_ACEPTANCE {
if !failed && percent < PERCENT_ACEPTANCE {
bot.delete_message(msg.chat.id, msg.id).await?;
let response = match id {
Some(i) => bot.send_photo(msg.chat.id, teloxide::types::InputFile::file_id(i.0)).has_spoiler(true),