def no_longer_afk(update, context): user = update.effective_user message = update.effective_message if not user: # ignore channels return if not is_user_afk(user.id): #Check if user is afk or not return end_afk_time = get_readable_time( (time.time() - float(REDIS.get(f'afk_time_{user.id}')))) REDIS.delete(f'afk_time_{user.id}') res = end_afk(user.id) if res: if message.new_chat_members: #dont say msg return firstname = update.effective_user.first_name try: rm_afkk = message.reply_text( "User <b>{}</b> Is No Longer AFK!\nYou Were AFK: <code>{}</code>" .format(firstname, end_afk_time), parse_mode="html") sleep(30) try: rm_afkk.delete() except BadRequest: pass except Exception: return
def check_afk(update, context, user_id, fst_name, userc_id): if is_user_afk(user_id): reason = afk_reason(user_id) since_afk = get_readable_time( (time.time() - float(REDIS.get(f'afk_time_{user_id}')))) if reason == "none": if int(userc_id) == int(user_id): return res = "User <b>{}</b> Is Currently AFK!\n\nLast Seen: <code>{}</code>".format( fst_name, since_afk) reply_afkk = update.effective_message.reply_text(res, parse_mode="html") sleep(60) try: reply_afkk.delete() except BadRequest: pass else: if int(userc_id) == int(user_id): return res = "User <b>{}</b> Is Currently AFK! \nSays It's Because Of:\n{}\n\nLast Seen: <code>{}</code>".format( fst_name, reason, since_afk) replly_afkk = update.effective_message.reply_text( res, parse_mode="html") sleep(60) try: replly_afkk.delete() except BadRequest: pass
def is_user_afk(userid): afk = REDIS.get(f'is_afk_{userid}') if afk: return True else: return False
def afk_reason(userid): return strb(REDIS.get(f'is_afk_{userid}'))
def is_user_afk(userid): rget = REDIS.get(f'is_afk_{userid}') if rget: return True else: return False