Example #1
0
async def no_longer_afk(c: TelePyroBot, m: Message):
    global afk_time
    global afk_start
    global afk_end
    global MENTIONED
    get = get_afk()
    if get and get["afk"]:
        back_alive = datetime.now()
        afk_end = back_alive.replace(microsecond=0)
        if afk_start != {}:
            total_afk_time = str((afk_end - afk_start))
        await c.send_message(
            PRIVATE_GROUP_ID, f"`No longer afk!\nWas AFk for: {total_afk_time}`"
        )
        set_afk(False, "")
        text = f"**Total {len(MENTIONED)} mentioned you**\n"
        for x in MENTIONED:
            msg_text = x["text"]
            if len(msg_text) >= 11:
                msg_text = f"{x['text']}..."
            text += "- [{}](https://t.me/c/{}/{}) ({}): `{}`\n".format(
                escape_markdown(x["user"]),
                x["chat_id"],
                x["message_id"],
                x["chat"],
                msg_text,
            )
        await c.send_message(PRIVATE_GROUP_ID, text)
        MENTIONED = []
        afk_time = None
        await m.stop_propagation()
Example #2
0
async def afk(c: TelePyroBot, m: Message):
    if PRIVATE_GROUP_ID is None:
        await m.edit_text(
            "<b><i>Please set the variable</b></i> `PRIVATE_GROUP_ID` for this to function."
        )
        return
    global afk_start
    afk_time = None
    afk_end = {}
    start_1 = datetime.now()
    afk_start = start_1.replace(microsecond=0)
    if len(m.text.split()) >= 2:
        await m.edit_text(
            f"I am going AFK now...\nBecause of {m.text.split(None, 1)[1]}"
        )
        await c.send_message(
            PRIVATE_GROUP_ID,
            f"You are AFK!\nBecause of {m.text.split(None, 1)[1]}",
        )
        await asyncio.sleep(2)
        await m.delete()
        await asyncio.sleep(2)
        set_afk(True, m.text.split(None, 1)[1])

    else:
        await m.edit_text(
            f"{mention_markdown(m.from_user.first_name, m.from_user.id)} is now AFK!"
        )
        await c.send_message(
            PRIVATE_GROUP_ID,
            f"{mention_markdown(m.from_user.first_name, m.from_user.id)} is now AFK!",
        )
        await asyncio.sleep(2)
        await m.delete()
        await asyncio.sleep(2)
        set_afk(True, "")
    return