def check_afk(bot, update, user_id, fst_name, userc_id): chat = update.effective_chat if sql.is_afk(user_id): user = sql.check_afk_status(user_id) if int(userc_id) == int(user_id): return res = (tld(chat.id, "status_afk_reason").format( fst_name, user.reason) if user.reason else tld( chat.id, "status_afk_noreason").format(fst_name)) update.effective_message.reply_text(res)
def check_afk(bot, update, user_id, fst_name): chat = update.effective_chat # type: Optional[Chat] if sql.is_afk(user_id): user = sql.check_afk_status(user_id) if not user.reason: res = tld(chat.id, f"{fst_name} is AFK!") else: res = tld( chat.id, f"{fst_name} is AFK! says its because of:\n{user.reason}") update.effective_message.reply_text(res)
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: 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, "{} is AFK!").format(fst_name) else: res = tl(update.effective_message, "{} is AFK! says its because of: {}").format( fst_name, reason) send_message(update.effective_message, res)