-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathbot.py
74 lines (47 loc) · 2.06 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import os
from PIL import Image
from pyrogram import Client,filters
from pyrogram.types import (InlineKeyboardButton, InlineKeyboardMarkup)
from pyrogram.errors.exceptions.bad_request_400 import UserNotParticipant
TOKEN = os.environ.get("TOKEN", "")
API_ID = int(os.environ.get("API_ID", 12345))
API_HASH = os.environ.get("API_HASH", "")
app = Client(
"pdf",
bot_token=TOKEN,api_hash=API_HASH,
api_id=API_ID
)
LIST = {}
@app.on_message(filters.command(['start']))
async def start(client, message):
await message.reply_text(text =f"""Hello {message.from_user.first_name }image to pdf bot
i can convert image to pdf
This bot created by @mrlokaman""",reply_to_message_id = message.message_id , reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton("Support 🇮🇳" ,url="https://t.me/lntechnical") ],
[InlineKeyboardButton("Subscribe 🧐", url="https://youtube.com/c/LNtechnical") ] ] ) )
@app.on_message(filters.private & filters.photo)
async def pdf(client,message):
if not isinstance(LIST.get(message.from_user.id), list):
LIST[message.from_user.id] = []
file_id = str(message.photo.file_id)
ms = await message.reply_text("Converting to PDF ......")
file = await client.download_media(file_id)
image = Image.open(file)
img = image.convert('RGB')
LIST[message.from_user.id].append(img)
await ms.edit(f"{len(LIST[message.from_user.id])} image Successful created PDF if you want add more image Send me One by one\n\n **if done click here 👉 /convert** ")
@app.on_message(filters.command(['convert']))
async def done(client,message):
images = LIST.get(message.from_user.id)
if isinstance(images, list):
del LIST[message.from_user.id]
if not images:
await message.reply_text( "No image !!")
return
path = f"{message.from_user.id}" + ".pdf"
images[0].save(path, save_all = True, append_images = images[1:])
await client.send_document(message.from_user.id, open(path, "rb"), caption = "Here your pdf !!")
os.remove(path)
app.run()