├── runtime.txt ├── Procfile ├── .github ├── FUNDING.yml └── workflows │ ├── pep8.yml │ └── devskim-analysis.yml ├── requirements.txt ├── README.md ├── app.json ├── LICENSE └── main.py /runtime.txt: -------------------------------------------------------------------------------- 1 | python-3.9.5 2 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | bughunter0: python3 main.py 2 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | ko_fi: nuhmanpk 2 | custom: ["https://paytm.me/yoB-s0a"] 3 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | pyrogram 2 | python-decouple 3 | tgcrypto 4 | PyPDF2 5 | humanize 6 | -------------------------------------------------------------------------------- /.github/workflows/pep8.yml: -------------------------------------------------------------------------------- 1 | - uses: actions/checkout@master 2 | with: 3 | ref: ${{ github.event.pull_request.head.sha }} 4 | - name: 'Run PEP8' 5 | uses: quentinguidee/pep8-action@v1 6 | with: 7 | arguments: '--max-line-length=80' 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # pyDF-Bot 3 | Pydf - Pyrogram Document File Bot, a modular Telegram Bot which provides Pdf Tools using PyPdf2 4 | Fork , Contribute, Move on 5 | 6 | # More to cover 7 | Merge, Rotate and Watermark are pending 🐱 8 | 9 | # Credits 10 | Pyrogram 11 | Pypdf2 12 | 13 | # No longer maintained 14 | -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Pydf Bot", 3 | "description": "A Modular telegram bot.", 4 | "repository": "https://github.com/bughunter0", 5 | "keywords": [ 6 | 7 | "telegram bot", 8 | "pyrogram" 9 | ], 10 | "env": { 11 | "BOT_TOKEN": { 12 | "description": "Your Bot token from @Botfather" 13 | }, 14 | "API_ID": { 15 | "description": "Your API_ID from https://my.telegram.org/apps" 16 | }, 17 | "API_HASH": { 18 | "description": "Your API_HASH from https://my.telegram.org/apps" 19 | } 20 | }, 21 | "buildpacks": [ 22 | { 23 | "url": "heroku/python" 24 | } 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /.github/workflows/devskim-analysis.yml: -------------------------------------------------------------------------------- 1 | # This workflow uses actions that are not certified by GitHub. 2 | # They are provided by a third-party and are governed by 3 | # separate terms of service, privacy policy, and support 4 | # documentation. 5 | 6 | name: DevSkim 7 | 8 | on: 9 | push: 10 | branches: [ main ] 11 | pull_request: 12 | branches: [ main ] 13 | schedule: 14 | - cron: '36 1 * * 1' 15 | 16 | jobs: 17 | lint: 18 | name: DevSkim 19 | runs-on: ubuntu-20.04 20 | permissions: 21 | actions: read 22 | contents: read 23 | security-events: write 24 | steps: 25 | - name: Checkout code 26 | uses: actions/checkout@v2 27 | 28 | - name: Run DevSkim scanner 29 | uses: microsoft/DevSkim-Action@v1 30 | 31 | - name: Upload DevSkim scan results to GitHub Security tab 32 | uses: github/codeql-action/upload-sarif@v1 33 | with: 34 | sarif_file: devskim-results.sarif 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Nuhman Pk 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import os 2 | from os import error, system, name 3 | import logging 4 | import pyrogram 5 | import PyPDF2 6 | import time 7 | from decouple import config 8 | from pyrogram import Client, filters 9 | from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, ForceReply 10 | from pyrogram.types import User, Message, Document 11 | 12 | 13 | 14 | bughunter0 = Client( 15 | "PyDF-BOT", 16 | bot_token = os.environ["BOT_TOKEN"], 17 | api_id = int(os.environ["API_ID"]), 18 | api_hash = os.environ["API_HASH"] 19 | ) 20 | START_STR = """ 21 | Hi **{}**, I'm PyDF Bot. I can Provide all Help regarding PDF file 22 | """ 23 | ABOUT = """ 24 | **BOT:** `PYDF BOT` 25 | **AUTHOR :** [bughunter0](https://t.me/bughunter0) 26 | **SERVER :** `Heroku` 27 | **LIBRARY :** `Pyrogram` 28 | **SOURCE :** [BugHunterBots](https://t.me/bughunterbots) 29 | **LANGUAGE :** `Python 3.9` 30 | """ 31 | HELP = """ 32 | Send me a pdf file to Move on 33 | """ 34 | 35 | DOWNLOAD_LOCATION = os.environ.get("DOWNLOAD_LOCATION", "./DOWNLOADS/PyDF/") 36 | # TXT_LOCATION = os.environ.get("TXT_LOCATION", "./DOWNLOADS/txt/") 37 | path = './DOWNLOADS/txt/bughunter0.txt' 38 | 39 | Disclaimer = """ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE """ 40 | 41 | START_BUTTON = InlineKeyboardMarkup( 42 | [[ 43 | InlineKeyboardButton('ABOUT',callback_data='cbabout'), 44 | InlineKeyboardButton('HELP',callback_data='cbhelp') 45 | ], 46 | [ 47 | InlineKeyboardButton('↗ JOIN HERE ↗', url='https://t.me/BughunterBots'), 48 | ]] 49 | 50 | ) 51 | CLOSE_BUTTON = InlineKeyboardMarkup( 52 | [[ 53 | InlineKeyboardButton('Back',callback_data='cbclose'), 54 | ]] 55 | ) 56 | 57 | @bughunter0.on_callback_query() # callbackQuery() 58 | async def cb_data(bot, update): 59 | if update.data == "cbhelp": 60 | await update.message.edit_text( 61 | text=HELP, 62 | reply_markup=CLOSE_BUTTON, 63 | disable_web_page_preview=True 64 | ) 65 | elif update.data == "cbabout": 66 | await update.message.edit_text( 67 | text=ABOUT, 68 | reply_markup=CLOSE_BUTTON, 69 | disable_web_page_preview=True 70 | ) 71 | else: 72 | await update.message.edit_text( 73 | text=START_STR.format(update.from_user.mention), 74 | disable_web_page_preview=True, 75 | reply_markup=START_BUTTON 76 | ) 77 | 78 | @bughunter0.on_message(filters.command(["start"])) # StartCommand 79 | async def start(bot, update): 80 | await update.reply_text( 81 | text=START_STR.format(update.from_user.mention), 82 | disable_web_page_preview=True, 83 | reply_markup=START_BUTTON 84 | ) 85 | 86 | @bughunter0.on_message(filters.document | (filters.document & filters.forwarded)) 87 | async def document(bot, message): 88 | message_id=int(message.message_id) 89 | chat_id=int(message.chat.id) 90 | await bot.send_message(text=" ◆ /pdf2txt - Extract text to Txt file \n ◆ /info to Get PDF information",reply_to_message_id=message_id,chat_id=chat_id) 91 | 92 | @bughunter0.on_message(filters.command(["pdf2txt"])) # PdfToText 93 | async def pdf_to_text(bot, message): 94 | try : 95 | if message.reply_to_message: 96 | pdf_path = DOWNLOAD_LOCATION + f"{message.chat.id}.pdf" #pdfFileObject 97 | txt = await message.reply("Downloading.....") 98 | await message.reply_to_message.download(pdf_path) 99 | await txt.edit("Downloaded File") 100 | pdf = open(pdf_path,'rb') 101 | pdf_reader = PyPDF2.PdfFileReader(pdf) #pdfReaderObject 102 | await txt.edit("Getting Number of Pages....") 103 | num_of_pages = pdf_reader.getNumPages() # Number of Pages 104 | await txt.edit(f"Found {num_of_pages} Page") 105 | page_no = pdf_reader.getPage(0) # pageObject 106 | await txt.edit("Extracting Text from PDF...") 107 | page_content = """ """ # EmptyString 108 | with open(f'{message.chat.id}.txt', 'a+') as text_path: 109 | for page in range (0,num_of_pages): 110 | file_write = open(f'{message.chat.id}.txt','a+') 111 | page_no = pdf_reader.getPage(page) # Iteration of page number 112 | page_content = page_no.extractText() 113 | file_write.write(f"\n page number - {page} \n") # writing Page Number as Title 114 | file_write.write(f" {page_content} ") # writing page content 115 | file_write.write(f"\n © BugHunterBots \n ") # Adding Page footer 116 | # await message.reply_text(f"**Page Number : {page} **\n\n ` {page_content} `\n @BugHunterBots\n\n") # Use this Line of code to get Pdf Text as Messages 117 | 118 | with open(f'{message.chat.id}.txt', 'a+') as text_path: 119 | await message.reply_document(f"{message.chat.id}.txt",caption="©@BugHunterBots") 120 | 121 | os.remove(pdf_path) 122 | os.remove(f"{message.chat.id}.txt") 123 | else : 124 | await message.reply("Please Reply to PDF file") 125 | except Exception as error : 126 | await txt.delete() 127 | await message.reply_text(f"{error}") 128 | os.remove(pdf_path) 129 | os.remove(f"{message.chat.id}.txt") 130 | 131 | @bughunter0.on_message(filters.command(["info"])) 132 | async def info(bot, message): 133 | try: 134 | if message.reply_to_message: 135 | txt = await message.reply_text("Validating Pdf ") 136 | pdf_path = DOWNLOAD_LOCATION + f"{message.chat.id}.pdf" #pdfFileObject 137 | await txt.edit("Downloading.....") 138 | await message.reply_to_message.download(pdf_path) 139 | await txt.edit("Downloaded File") 140 | pdf = open(pdf_path,'rb') 141 | pdf_reader = PyPDF2.PdfFileReader(pdf) #pdfReaderObject 142 | await txt.edit("Getting Number of Pages....") 143 | num_of_pages = pdf_reader.getNumPages() 144 | await txt.edit(f"Found {num_of_pages} Page") 145 | await txt.edit("Getting PDF info..") 146 | info = pdf_reader.getDocumentInfo() 147 | await txt.edit(f""" 148 | **Author :** `{info.author}` 149 | **Creator :** `{info.creator}` 150 | **Producer :** `{info.producer}` 151 | **Subject :** `{info.subject}` 152 | **Title :** `{info.title}` 153 | **Pages :** `{num_of_pages}`""") 154 | 155 | os.remove(pdf_path) 156 | else: 157 | await message.reply_text("Please Reply to a Pdf File") 158 | except Exception as error : 159 | await message.reply_text(f"Oops , {error}") 160 | 161 | # @bughunter0.on_message(filters.command(["merge"])) # will Be added Soon 162 | 163 | bughunter0.run() 164 | --------------------------------------------------------------------------------