Exemplo n.º 1
0
def reply_afk(bot: Bot, update: Update):

    message = update.effective_message
    entities = message.parse_entities(
        [MessageEntity.TEXT_MENTION, MessageEntity.MENTION])

    if message.entities and entities:
        for ent in entities:
            if ent.type == MessageEntity.TEXT_MENTION:
                user_id = ent.user.id
                fst_name = ent.user.first_name

            elif ent.type == MessageEntity.MENTION:
                user_id = get_user_id(message.text[ent.offset:ent.offset +
                                                   ent.length])
                if not user_id:
                    return
                chat = bot.get_chat(user_id)
                fst_name = chat.first_name

            else:
                return

            if sql.is_afk(user_id):
                valid, reason = sql.check_afk_status(user_id)
                if valid:
                    if not reason:
                        res = "{} is AFK!".format(fst_name)
                    else:
                        res = "{} is AFK!\nReason:\n{}".format(
                            fst_name, reason)
                    message.reply_text(res)
Exemplo n.º 2
0
def __user_info__(user_id):
    text = "\n\nCurrently AFK : <b>{}</b>"
    if sql.is_afk(user_id):
        text = text.format("Yes")
        user = sql.check_afk_status(user_id)
        if user.reason:
            text += "\nRsn : <code>{}</code>".format(html.escape(user.reason))
    else:
        text = text.format("No")
    return text
Exemplo n.º 3
0
def check_afk(bot, update, user_id, fst_name, userc_id):
    chat = update.effective_chat  # type: Optional[Chat]
    if sql.is_afk(user_id):
        user = sql.check_afk_status(user_id)
        if not user.reason:
            if int(userc_id) == int(user_id):
                return
            res = "{} is afk".format(fst_name)
            update.effective_message.reply_text(res)
        else:
            if int(userc_id) == int(user_id):
                return
            res = "{} is afk.\nReason: {}".format(fst_name, user.reason)
            update.effective_message.reply_text(res)
Exemplo n.º 4
0
def check_afk(bot, update, user_id, fst_name, userc_id):
    afk_time = time_formatter(round(time.time() - TIME))
    if sql.is_afk(user_id):
        user = sql.check_afk_status(user_id)
        if not user.reason:
            if int(userc_id) == int(user_id):
                return
            res = "{} IS AFK! \n\nLast Seen: {} ago".format(fst_name, afk_time)
            update.effective_message.reply_text(res)
        else:
            if int(userc_id) == int(user_id):
                return
            res = "{} IS AFK! \nLast Seen: {} ago \n\nReason: {}".format(
                fst_name, afk_time, user.reason)
            update.effective_message.reply_text(res)