Esempio n. 1
0
def reply_afk(bot: Bot, update: Update):
    message = update.effective_message  # type: Optional[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:
                    # Should never happen, since for a user to become AFK they must have spoken. Maybe changed username?
                    return
                try:
                    chat = bot.get_chat(user_id)
                except BadRequest:
                    print("Error: Could not fetch userid {} for AFK module".format(user_id))
                    return
                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 = tl(update.effective_message, "{} sedang AFK!").format(fst_name)
                    else:
                        res = tl(update.effective_message, "{} sedang AFK!\nKarena : {}").format(fst_name, reason)
                    send_message(update.effective_message, res)
Esempio n. 2
0
def reply_afk(bot: Bot, update: Update):
    message = update.effective_message  # type: Optional[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:
                    # Should never happen, since for a user to become AFK they must have spoken. Maybe changed username?
                    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 = "{} sedang AFK!".format(fst_name)
                    else:
                        res = "{} sedang AFK!\nKarena : {}".format(
                            fst_name, reason)
                    message.reply_text(res)