-
Notifications
You must be signed in to change notification settings - Fork 22
/
demotivator.py
85 lines (77 loc) · 3.33 KB
/
demotivator.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
import random
from io import BytesIO
from pyrogram import Client, filters
from pyrogram.types import Message
from utils.misc import modules_help, prefix
from utils.scripts import import_library
requests = import_library("requests")
PIL = import_library("PIL", "pillow")
from PIL import Image, ImageDraw, ImageFont
@Client.on_message(filters.command(["dem"], prefix) & filters.me)
async def demotivator(client: Client, message: Message):
await message.edit("<code>Process of demotivation...</code>")
font = requests.get(
"https://github.com/Dragon-Userbot/files/blob/main/Times%20New%20Roman.ttf?raw=true"
)
f = font.content
template_dem = requests.get(
"https://raw.githubusercontent.com/Dragon-Userbot/files/main/demotivator.png"
)
if message.reply_to_message:
words = ["random", "text", "typing", "fuck"]
if message.reply_to_message.photo:
donwloads = await client.download_media(
message.reply_to_message.photo.file_id
)
photo = Image.open(f"{donwloads}")
resize_photo = photo.resize((469, 312))
text = (
message.text.split(" ", maxsplit=1)[1]
if len(message.text.split()) > 1
else random.choice(words)
)
im = Image.open(BytesIO(template_dem.content))
im.paste(resize_photo, (65, 48))
text_font = ImageFont.truetype(BytesIO(f), 22)
text_draw = ImageDraw.Draw(im)
text_draw.multiline_text(
(299, 412), text, font=text_font, fill=(255, 255, 255), anchor="ms"
)
im.save(f"downloads/{message.message_id}.png")
await message.reply_to_message.reply_photo(
f"downloads/{message.message_id}.png"
)
await message.delete()
elif message.reply_to_message.sticker:
if not message.reply_to_message.sticker.is_animated:
donwloads = await client.download_media(
message.reply_to_message.sticker.file_id
)
photo = Image.open(f"{donwloads}")
resize_photo = photo.resize((469, 312))
text = (
message.text.split(" ", maxsplit=1)[1]
if len(message.text.split()) > 1
else random.choice(words)
)
im = Image.open(BytesIO(template_dem.content))
im.paste(resize_photo, (65, 48))
text_font = ImageFont.truetype(BytesIO(f), 22)
text_draw = ImageDraw.Draw(im)
text_draw.multiline_text(
(299, 412), text, font=text_font, fill=(255, 255, 255), anchor="ms"
)
im.save(f"downloads/{message.message_id}.png")
await message.reply_to_message.reply_photo(
f"downloads/{message.message_id}.png"
)
await message.delete()
else:
await message.edit("<b>Animated stickers are not supported</b>")
else:
await message.edit("<b>Need to answer the photo/sticker</b>")
else:
await message.edit("<b>Need to answer the photo/sticker</b>")
modules_help["demotivator"] = {
"dem [text]*": "Reply to the picture to make a demotivator out of it"
}