-
-
Notifications
You must be signed in to change notification settings - Fork 346
/
Copy pathstickerfun.py
126 lines (116 loc) · 4.19 KB
/
stickerfun.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import io
import os
import random
import textwrap
import re
from PIL import Image, ImageDraw, ImageFont
from telethon.tl.types import InputMessagesFilterDocument
from ULTRA import CMD_HELP, bot
from ULTRA.utils import admin_cmd, edit_or_reply, sudo_cmd
from ULTRA.helpers.functions import deEmojify
# RegEx by https://t.me/c/1220993104/50065
@bot.on(admin_cmd(outgoing=True, pattern="waifu(?: |$)(.*)"))
@bot.on(sudo_cmd(pattern="waifu(?: |$)(.*)"))
async def waifu(animu):
# """Creates random anime sticker!"""
text = animu.pattern_match.group(1)
if not text:
if animu.is_reply:
text = (await animu.get_reply_message()).message
else:
await animu.edit("`You haven't written any article, Waifu is going away.`")
return
animus = [1, 3, 7, 9, 13, 22, 34, 35, 36, 37, 43, 44, 45, 52, 53, 55]
sticcers = await bot.inline_query(
"stickerizerbot", f"#{random.choice(animus)}{(deEmojify(text))}"
)
await sticcers[0].click(
animu.chat_id,
reply_to=animu.reply_to_msg_id,
silent=True if animu.is_reply else False,
hide_via=True,
)
await animu.delete()
@bot.on(admin_cmd(pattern=r"stcr ?(?:(.*?) \| )?(.*)", outgoing=True))
@bot.on(sudo_cmd(pattern=r"stcr ?(?:(.*?) \| )?(.*)", allow_sudo=True))
async def sticklet(event):
R = random.randint(0, 256)
G = random.randint(0, 256)
B = random.randint(0, 256)
reply_message = event.message
# get the input text
# the text on which we would like to do the magic on
font_file_name = event.pattern_match.group(1)
if not font_file_name:
font_file_name = ""
sticktext = event.pattern_match.group(2)
if not sticktext:
if event.reply_to_msg_id:
reply_message = await event.get_reply_message()
sticktext = reply_message.message
else:
await edit_or_reply(event, "Need something 🙄")
return
if event.reply_to_msg_id:
reply_message = await event.get_reply_message()
# delete the userbot command,
# i don't know why this is required
await event.delete()
sticktext = deEmojify(sticktext)
# https://docs.python.org/3/library/textwrap.html#textwrap.wrap
sticktext = textwrap.wrap(sticktext, width=10)
# converts back the list to a string
sticktext = "\n".join(sticktext)
image = Image.new("RGBA", (512, 512), (255, 255, 255, 0))
draw = ImageDraw.Draw(image)
fontsize = 230
FONT_FILE = await get_font_file(event.client, "@catfonts", font_file_name)
font = ImageFont.truetype(FONT_FILE, size=fontsize)
while draw.multiline_textsize(sticktext, font=font) > (512, 512):
fontsize -= 3
font = ImageFont.truetype(FONT_FILE, size=fontsize)
width, height = draw.multiline_textsize(sticktext, font=font)
draw.multiline_text(
((512 - width) / 2, (512 - height) / 2), sticktext, font=font, fill=(R, G, B)
)
image_stream = io.BytesIO()
image_stream.name = "LEGENDBOT.webp"
image.save(image_stream, "WebP")
image_stream.seek(0)
# finally, reply the sticker
await event.client.send_file(
event.chat_id,
image_stream,
caption="helbot's Sticklet",
reply_to=event.message.reply_to_msg_id,
)
# cleanup
try:
os.remove(FONT_FILE)
except BaseException:
pass
async def get_font_file(client, channel_id, search_kw=""):
# first get the font messages
font_file_message_s = await client.get_messages(
entity=channel_id,
filter=InputMessagesFilterDocument,
# this might cause FLOOD WAIT,
# if used too many times
limit=None,
search=search_kw,
)
# get a random font from the list of fonts
# https://docs.python.org/3/library/random.html#random.choice
font_file_message = random.choice(font_file_message_s)
# download and return the file path
return await client.download_media(font_file_message)
CMD_HELP.update(
{
"stickerfun": "**Plugin : **`stickerfun`\
\n\n**Syntax : **`.waifu` <your txt>\
\n**Usage : **Anime that makes your writing fun.\
\n\n**Syntax : **`.stcr` <your txt>\
\n**Usage : **your text as sticker\
"
}
)