-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmain.py
90 lines (72 loc) · 2.23 KB
/
main.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import os
import glitchart
from dotenv import load_dotenv
from pyrogram import Client, filters
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
load_dotenv()
Bot = Client(
"Glitch-Art-Bot",
bot_token = os.environ.get("BOT_TOKEN"),
api_id = int(os.environ.get("API_ID")),
api_hash = os.environ.get("API_HASH")
)
START_TEXT = """Hello {},
I am a photo to glitch art telegram bot. \
Send a photo, I will send glitch art photo.
Made by @FayasNoushad"""
START_BUTTONS = InlineKeyboardMarkup(
[
[
InlineKeyboardButton('Channel', url='https://telegram.me/FayasNoushad'),
InlineKeyboardButton('Feedback', url='https://telegram.me/TheFayas')
]
]
)
PATH = os.environ.get("PATH", "./DOWNLOADS")
@Bot.on_message(filters.private & filters.command(["start"]))
async def start(bot, update):
await update.reply_text(
text=START_TEXT.format(update.from_user.mention),
reply_markup=START_BUTTONS,
disable_web_page_preview=True,
quote=True
)
@Bot.on_message(filters.private & filters.photo)
async def glitch_art(bot, update):
download_path = PATH + "/" + str(update.from_user.id) + "/"
download_location = download_path + "photo.jpg"
message = await update.reply_text(
text="`Processing...`",
disable_web_page_preview=True,
quote=True
)
try:
await update.download(
file_name=download_location
)
except Exception as error:
await message.edit_text(
text=f"**Error :** `{error}`\nContact @FayasNoushad.",
disable_web_page_preview=True
)
return
await message.edit_text(
text="`Converting to glitch art...`"
)
try:
glitch_art = glitchart.jpeg(download_location)
await update.reply_photo(
photo=glitch_art,
caption=update.caption,
quote=True
)
os.remove(download_location)
os.remove(glitch_art)
except Exception as error:
await message.edit_text(
text=f"**Error :** `{error}`\nContact @TheFayas.",
disable_web_page_preview=True
)
return
await message.delete()
Bot.run()