def reply_afk(update, context): 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 = context.bot.get_chat(user_id) except BadRequest: print("Error in afk can't get user id {}".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 = "Hang on... {} away from keyboard!".format(fst_name) else: res = "{} is away from keyboard! says it's because of: \n{}".format(fst_name, reason) send_message(update.effective_message, res)
def __user_info__(user_id): is_afk = sql.is_afk(user_id) text = "<b>Currently AFK</b>: {}" if is_afk: text = text.format("Yes") else: text = text.format("No") return text