# < Source - t.me/testingpluginnn >
# < https://github.com/TeamUltroid/Ultroid >

"""
✘ Generate Fake YT comments!

• **CMD:**
> `{i}ytc message` <reply>
> `{i}ytc username ; message`
"""

from urllib.parse import quote
from telethon.utils import get_display_name

from . import udB


CO_API = "https://some-random-api.ml/canvas/youtube-comment?avatar={0}&username={1}&comment={2}"
AVATAR = "https://i.ibb.co/Tcn6S93/109945.jpg"

@ultroid_cmd(pattern="ytc")
async def yt_comment(e):
    reply = await e.get_reply_message()
    try:
        args = e.text.split(maxsplit=1)[1]
    except:
        return await e.eor("Gib some text as well!", time=8)

    msg = await e.eor("`Generating yt comment..!`")
    user = get_display_name(reply.sender) if reply else ultroid.full_name
    if ";" in args:
        args, user = args.split(";", 1)
    args, user = quote(args.strip()), quote(user.strip())
    fnx = CO_API.format(udB.get_key("YTC_AVATAR") or AVATAR, user, args)
    try:
        await e.client.send_file(e.chat_id,
            fnx, silent=True, reply_to=e.reply_to_msg_id,
            caption="**Fake YouTube Comment Generated!**")
        await msg.delete()
    except Exception as ex:
        return await msg.edit(f"**Got Error!** \n> `{ex}`")
