MissKatyPyro/misskaty/plugins/fun.py
yasirarism 9cb6a7d77d
Major change with own custom client decorator (#170)
* Add kbbi and carbon

* add blacklist command

* style: format code with black and isort (#168)

Format code with black and isort

This commit fixes the style issues introduced in bffcf61 according to the output
from Black and isort.

Details: https://app.deepsource.com/gh/yasirarism/MissKatyPyro/transform/4ddb51cc-a1ca-432a-95c4-1fb5388b405a/

Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>

* okk

* style: format code with black and isort (#169)

Format code with black and isort

This commit fixes the style issues introduced in 9355c09 according to the output
from Black and isort.

Details: https://app.deepsource.com/gh/yasirarism/MissKatyPyro/transform/172890f8-d001-4812-8380-9a666a9a3bd5/

Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>

* jmm

---------

Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
2023-07-05 13:10:44 +07:00

180 lines
No EOL
5.7 KiB
Python

import textwrap
from asyncio import gather
from os import remove as hapus
from PIL import Image, ImageDraw, ImageFont
from pyrogram import filters
from misskaty import app
from misskaty.core.decorator.errors import capture_err
from misskaty.core.decorator.ratelimiter import ratelimiter
from misskaty.helper.localization import use_chat_lang
from misskaty.vars import COMMAND_HANDLER
async def draw_meme_text(image_path, text):
img = Image.open(image_path)
hapus(image_path)
i_width, i_height = img.size
m_font = ImageFont.truetype(
"assets/MutantAcademyStyle.ttf", int((70 / 640) * i_width)
)
if ";" in text:
upper_text, lower_text = text.split(";")
else:
upper_text = text
lower_text = ""
draw = ImageDraw.Draw(img)
current_h, pad = 10, 5
if upper_text:
for u_text in textwrap.wrap(upper_text, width=15):
u_width, u_height = draw.textsize(u_text, font=m_font)
draw.text(
xy=(((i_width - u_width) / 2) - 1, int((current_h / 640) * i_width)),
text=u_text,
font=m_font,
fill=(0, 0, 0),
stroke_width=3,
stroke_fill="black",
)
draw.text(
xy=(((i_width - u_width) / 2) + 1, int((current_h / 640) * i_width)),
text=u_text,
font=m_font,
fill=(0, 0, 0),
stroke_width=3,
stroke_fill="black",
)
draw.text(
xy=((i_width - u_width) / 2, int(((current_h / 640) * i_width)) - 1),
text=u_text,
font=m_font,
fill=(0, 0, 0),
stroke_width=3,
stroke_fill="black",
)
draw.text(
xy=(((i_width - u_width) / 2), int(((current_h / 640) * i_width)) + 1),
text=u_text,
font=m_font,
fill=(0, 0, 0),
stroke_width=3,
stroke_fill="black",
)
draw.text(
xy=((i_width - u_width) / 2, int((current_h / 640) * i_width)),
text=u_text,
font=m_font,
fill=(255, 255, 255),
)
current_h += u_height + pad
if lower_text:
for l_text in textwrap.wrap(lower_text, width=15):
u_width, u_height = draw.textsize(l_text, font=m_font)
draw.text(
xy=(
((i_width - u_width) / 2) - 1,
i_height - u_height - int((20 / 640) * i_width),
),
text=l_text,
font=m_font,
fill=(0, 0, 0),
stroke_width=3,
stroke_fill="black",
)
draw.text(
xy=(
((i_width - u_width) / 2) + 1,
i_height - u_height - int((20 / 640) * i_width),
),
text=l_text,
font=m_font,
fill=(0, 0, 0),
stroke_width=3,
stroke_fill="black",
)
draw.text(
xy=(
(i_width - u_width) / 2,
(i_height - u_height - int((20 / 640) * i_width)) - 1,
),
text=l_text,
font=m_font,
fill=(0, 0, 0),
stroke_width=3,
stroke_fill="black",
)
draw.text(
xy=(
(i_width - u_width) / 2,
(i_height - u_height - int((20 / 640) * i_width)) + 1,
),
text=l_text,
font=m_font,
fill=(0, 0, 0),
stroke_width=3,
stroke_fill="black",
)
draw.text(
xy=(
(i_width - u_width) / 2,
i_height - u_height - int((20 / 640) * i_width),
),
text=l_text,
font=m_font,
fill=(255, 255, 255),
stroke_width=3,
stroke_fill="black",
)
current_h += u_height + pad
webp_file = "misskatyfy.webp"
png_file = "misskatyfy.png"
new_size = (512, 512)
img.resize(new_size)
img.save(webp_file, "WebP")
img.save(png_file, "PNG")
img.close()
return webp_file, png_file
@app.on_message(filters.command(["mmf"], COMMAND_HANDLER))
@capture_err
@ratelimiter
async def memify(client, message):
if message.reply_to_message and (
message.reply_to_message.sticker or message.reply_to_message.photo
):
try:
file = await message.reply_to_message.download()
webp, png = await draw_meme_text(
file, message.text.split(None, 1)[1].strip()
)
await gather(*[message.reply_document(png), message.reply_sticker(webp)])
try:
hapus(webp)
hapus(png)
except:
pass
except Exception as err:
try:
hapus(webp)
hapus(png)
except:
pass
await message.reply_msg(f"ERROR: {err}")
else:
await message.reply_msg(
"Gunakan command <b>/mmf <text></b> dengan reply ke sticker, pisahkan dengan ; untuk membuat posisi text dibawah."
)
@app.on_message(filters.command(["dice"], COMMAND_HANDLER))
@use_chat_lang()
async def dice(c, m, strings):
dices = await c.send_dice(m.chat.id, reply_to_message_id=m.id)
await dices.reply_msg(strings("result").format(number=dices.dice.value), quote=True)