-
Notifications
You must be signed in to change notification settings - Fork 1
/
custom_thumbnail.py
70 lines (60 loc) · 2.12 KB
/
custom_thumbnail.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
import logging
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
import numpy
import os
from PIL import Image
import time
if bool(os.environ.get("WEBHOOK", False)):
from sample_config import Config
else:
from config import Config
from translation import Translation
import pyrogram
from pyrogram import Client, filters
logging.getLogger("pyrogram").setLevel(logging.WARNING)
from database.blacklist import check_blacklist
from database.userchats import add_chat
@Client.on_message(filters.photo)
async def save_photo(bot, update):
fuser = update.from_user.id
if check_blacklist(fuser):
await update.reply_text("Sorry! You are Banned!")
return
add_chat(fuser)
if update.media_group_id is not None:
# album is sent
download_location = Config.DOWNLOAD_LOCATION + "/" + str(update.from_user.id) + "/" + str(update.media_group_id) + "/"
# create download directory, if not exist
if not os.path.isdir(download_location):
os.makedirs(download_location)
await bot.download_media(
message=update,
file_name=download_location
)
else:
# received single photo
download_location = Config.DOWNLOAD_LOCATION + "/" + str(update.from_user.id) + ".jpg"
await bot.download_media(
message=update,
file_name=download_location
)
await bot.send_message(
chat_id=update.chat.id,
text=Translation.SAVED_CUSTOM_THUMB_NAIL,
reply_to_message_id=update.message_id
)
@Client.on_message(filters.command("deletethumbnail"))
async def delete_thumbnail(bot, update):
download_location = Config.DOWNLOAD_LOCATION + "/" + str(update.from_user.id)
try:
os.remove(download_location + ".jpg")
# os.remove(download_location + ".json")
except:
pass
await bot.send_message(
chat_id=update.chat.id,
text=Translation.DEL_ETED_CUSTOM_THUMB_NAIL,
reply_to_message_id=update.message_id
)