diff --git a/Handles/HandleInformation.cs b/Handles/HandleInformation.cs index 8afafc3..6c7d3f1 100644 --- a/Handles/HandleInformation.cs +++ b/Handles/HandleInformation.cs @@ -110,11 +110,14 @@ async public Task SendDocument() { foreach (string fatura in respostas) { - if (fatura == "None" || fatura == null || fatura == "") - { - continue; - } - await using Stream stream = System.IO.File.OpenRead(@$"{cfg.CURRENT_PATH}\tmp\{fatura}"); + if (fatura == "None" || fatura == null || fatura == "") continue; + if(!PdfChecker.PdfCheck($"./tmp/{fatura}", request.informacao!)) + throw new InvalidOperationException("ERRO: A fatura recuperada não corresponde com a solicitada!"); + } + foreach (string fatura in respostas) + { + if (fatura == "None" || fatura == null || fatura == "") continue; + await using Stream stream = System.IO.File.OpenRead($"./tmp/{fatura}"); await bot.SendDocumentAsyncWraper(user.id, stream, fatura); stream.Dispose(); await bot.sendTextMesssageWraper(user.id, fatura, false); diff --git a/Helpers/PdfChecker.cs b/Helpers/PdfChecker.cs new file mode 100644 index 0000000..eeeb1d7 --- /dev/null +++ b/Helpers/PdfChecker.cs @@ -0,0 +1,27 @@ +namespace telbot; +public static class PdfChecker +{ + public static bool PdfCheck(String filepath, String instalacao) + { + try + { + if(!System.IO.File.Exists(filepath)) return false; + var reader = new iTextSharp.text.pdf.PdfReader(filepath); + var text = new System.Text.StringBuilder(); + for (int page = 1; page <= reader.NumberOfPages; page++) { + var strategy = new iTextSharp.text.pdf.parser.SimpleTextExtractionStrategy(); + string currentText = iTextSharp.text.pdf.parser.PdfTextExtractor.GetTextFromPage(reader, page, strategy); + currentText = System.Text.Encoding.UTF8.GetString(System.Text.ASCIIEncoding.Convert( + System.Text.Encoding.Default, System.Text.Encoding.UTF8, System.Text.Encoding.Default.GetBytes(currentText))); + text.Append(currentText); + } + reader.Close(); + String result = text.ToString(); + return result.Contains(instalacao); + } + catch + { + return false; + } + } +} diff --git a/telbot.csproj b/telbot.csproj index fb8f85b..258de98 100644 --- a/telbot.csproj +++ b/telbot.csproj @@ -12,6 +12,7 @@ +