from html import escape
from random import choice
from pyrogram import enums
from pyrogram.errors import MessageTooLong
from pyrogram.types import Message
from Powers import DEV_USERS
from Powers.bot_class import Gojo
from Powers.utils import extras
from Powers.utils.custom_filters import command
from Powers.utils.extras import NOWYES as NO
from Powers.utils.extras import YESWNO as YES
@Gojo.on_message(command("shout"))
async def fun_shout(_, m: Message):
    if len(m.text.split()) == 1:
        await m.reply_text(
            text="Please check help on how to use this this command.",
            quote=True,
        )
        return
    try:
        text = " ".join(m.text.split(None, 1)[1])
        result = [" ".join(list(text))]
        result.extend(
            f"{symbol} " + "  " * pos + symbol
            for pos, symbol in enumerate(text[1:])
        )
        result = list("\n".join(result))
        result[0] = text[0]
        result = "".join(result)
        msg = "```\n" + result + "```"
        await m.reply_text(msg, parse_mode=enums.ParseMode.MARKDOWN)
        return
    except MessageTooLong as e:
        await m.reply_text(f"Error: {e}")
        return
@Gojo.on_message(command("runs"))
async def fun_run(_, m: Message):
    await m.reply_text(choice(extras.RUN_STRINGS))
    return
@Gojo.on_message(command("slap"))
async def fun_slap(c: Gojo, m: Message):
    me = await c.get_me()
    reply_text = m.reply_to_message.reply_text if m.reply_to_message else m.reply_text
    curr_user = escape(m.from_user.first_name)
    user = m.reply_to_message.from_user if m.reply_to_message else m.from_user
    user_id = user.id
    if user_id == me.id:
        temp = choice(extras.SLAP_GOJO_TEMPLATES)
    else:
        temp = choice(extras.SLAP_TEMPLATES)
    if user_id != m.from_user.id:
        user1 = curr_user
        user2 = user.first_name
    else:
        user1 = me.first_name
        user2 = curr_user
    item = choice(extras.ITEMS)
    hit = choice(extras.HIT)
    throw = choice(extras.THROW)
    reply = temp.format(user1=user1, user2=user2, item=item, hits=hit, throws=throw)
    await reply_text(reply)
    return
@Gojo.on_message(command("roll"))
async def fun_roll(_, m: Message):
    reply_text = m.reply_to_message.reply_text if m.reply_to_message else m.reply_text
    await reply_text(choice(range(1, 7)))
    return
@Gojo.on_message(command("toss"))
async def fun_toss(_, m: Message):
    reply_text = m.reply_to_message.reply_text if m.reply_to_message else m.reply_text
    await reply_text(choice(extras.TOSS))
    return
@Gojo.on_message(command("insult"))
async def insult(c: Gojo, m: Message):
    if not m.reply_to_message:
        await m.reply_text("You want to insult yourself such a foolish person.\nYou are not even worth insulting")
        return
    user_id = m.reply_to_message.from_user.id
    user_first_name = m.reply_to_message.from_user.first_name
    if user_id in DEV_USERS:
        await m.reply_text("Sorry! I can't insult my devs....")
    else:
        Insult_omp = choice(extras.INSULT_STRINGS)
        await m.reply_to_message.reply_text(Insult_omp)
@Gojo.on_message(command("yes"))
async def yesw(c: Gojo, m: Message):
    reply_text = m.reply_to_message.reply_text if m.reply_to_message else m.reply_text
    rtext = YES[0]
    await reply_text(rtext)
    return
@Gojo.on_message(command("no"))
async def now(c: Gojo, m: Message):
    reply_text = m.reply_to_message.reply_text if m.reply_to_message else m.reply_text
    rtext = NO[0]
    await reply_text(rtext)
    return
@Gojo.on_message(command("shrug"))
async def fun_shrug(_, m: Message):
    reply_text = m.reply_to_message.reply_text if m.reply_to_message else m.reply_text
    await reply_text(r"¯\_(ツ)_/¯")
    return
@Gojo.on_message(command("bluetext"))
async def fun_bluetext(_, m: Message):
    reply_text = m.reply_to_message.reply_text if m.reply_to_message else m.reply_text
    await reply_text(
        "|| /BLUE /TEXT\n/MUST /CLICK\n/I /AM /A /STUPID /ANIMAL /THAT /IS /ATTRACTED /TO /COLORS ||",
    )
    return
@Gojo.on_message(command("decide"))
async def fun_decide(_, m: Message):
    reply_text = m.reply_to_message.reply_text if m.reply_to_message else m.reply_text
    await reply_text(choice(extras.DECIDE))
    return
@Gojo.on_message(command("react"))
async def fun_table(_, m: Message):
    reply_text = m.reply_to_message.reply_text if m.reply_to_message else m.reply_text
    await reply_text(choice(extras.REACTIONS))
    return
@Gojo.on_message(command("weebify"))
async def weebify(_, m: Message):
    if len(m.text.split()) >= 2:
        args = m.text.split(None, 1)[1]
    elif m.reply_to_message and len(m.text.split()) == 1:
        args = m.reply_to_message.text
    else:
        await m.reply_text(
            "Please reply to a message or enter text after command to weebify it.",
        )
        return
    if not args:
        await m.reply_text(text="What am I supposed to Weebify?")
        return
    # Use split to convert to list
    # Not using list itself becuase black changes it to long format...
    normiefont = "a b c d e f g h i j k l m n o p q r s t u v w x y z".split()
    weebyfont = "卂 乃 匚 刀 乇 下 厶 卄 工 丁 长 乚 从 𠘨 口 尸 㔿 尺 丂 丅 凵 リ 山 乂 丫 乙".split()
    string = "  ".join(args).lower()
    for normiecharacter in string:
        if normiecharacter in normiefont:
            weebycharacter = weebyfont[normiefont.index(normiecharacter)]
            string = string.replace(normiecharacter, weebycharacter)
    await m.reply_text(
        text=f"""Weebified String:
        {string}"""
    )
    return
__PLUGIN__ = "fun"
_DISABLE_CMDS_ = [
    "weebify",
    "decide",
    "react",
    "bluetext",
    "toss",
    "yes",
    "no",
    "roll",
    "slap",
    "runs",
    "shout",
    "insult",
    "shrug",
]
__HELP__ = """
**Fun**
• /runs: reply a random string from an array of replies.
• /slap: slap a user, or get slapped if not a reply.
• /insult: to insult a user, or get insulted if not a reply
• /shrug : get shrug XD.
• /decide : Randomly answers yes/no/maybe
• /toss : Tosses A coin
• /yes : check urself :V
• /no : check urself :V
• /bluetext : check urself :V
• /roll : Roll a dice.
• /react : Random Reaction
• /shout ``: write anything you want to give loud shout."""