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: message.reply_text( "{} is no longer AFK!\nTime you were AFK for: {}".format( firstname, end_afk_time ) ) except Exception: return
def reply_filter(update: Update, context: CallbackContext) -> str: chat: Optional[Chat] = update.effective_chat message: Optional[Message] = update.effective_message user: Optional[User] = update.effective_user chat_id = str(chat.id)[1:] approve_list = list(REDIS.sunion(f"approve_list_{chat_id}")) is_user_approved = mention_html(user.id, user.first_name) if is_user_approved in approve_list: return if not user: # Ignore channel return if user.id == 777000: return chat_warn_filters = sql.get_chat_warn_triggers(chat.id) to_match = extract_text(message) if not to_match: return "" for keyword in chat_warn_filters: pattern = r"( |^|[^\w])" + re.escape(keyword) + r"( |$|[^\w])" if re.search(pattern, to_match, flags=re.IGNORECASE): user: Optional[User] = update.effective_user warn_filter = sql.get_warn_filter(chat.id, keyword) return warn(user, chat, warn_filter.reply, message) return ""
def afk(update, context): args = update.effective_message.text.split(None, 1) user = update.effective_user if not user: # ignore channels return if user.id == 777000: return start_afk_time = time.time() if len(args) >= 2: reason = args[1] else: reason = "none" start_afk(update.effective_user.id, reason) REDIS.set(f"afk_time_{update.effective_user.id}", start_afk_time) fname = update.effective_user.first_name try: update.effective_message.reply_text("{} is now Away!".format(fname)) except BadRequest: pass
def __user_info__(user_id): is_afk = is_user_afk(user_id) text = "" if is_afk: since_afk = get_readable_time( (time.time() - float(REDIS.get(f"afk_time_{user_id}"))) ) text = "<i>This user is currently afk (away from keyboard).</i>" text += f"\n<i>Since: {since_afk}</i>" else: text = "<i>This user is currently isn't afk (away from keyboard).</i>" return text
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 = "{} is AFK!\nSince: {}".format(fst_name, since_afk) update.effective_message.reply_text(res) else: if int(userc_id) == int(user_id): return res = "{} is AFK! Says it's because of:\n{}\nSince: {}".format( fst_name, reason, since_afk ) update.effective_message.reply_text(res)
def is_user_afk(userid): rget = REDIS.get(f"is_afk_{userid}") if rget: return True else: return False
def end_afk(userid): REDIS.delete(f"is_afk_{userid}") return True
def afk_reason(userid): return strb(REDIS.get(f"is_afk_{userid}"))
def start_afk(userid, reason): REDIS.set(f"is_afk_{userid}", reason)