def filter(self, message): if not check_ban_state(message.chat_id, BanMessageType.FLOOD): return False chat_data: dict = get_chat_data(chat_id=message.chat_id) time = chat_data.get(ChatData.FLOOD_TIME) num = chat_data.get(ChatData.FLOOD_NUM) if not time or not num: return now_time = datetime.now().timestamp() user_data = get_user_data(message.from_user.id) msg_data = user_data.get(UserData.MSG_DATA, []) if len(msg_data) < num: msg_data.append(now_time) user_data["msg_data"] = msg_data return False liimt_time = now_time - time if msg_data[-1] < liimt_time: msg_data = [now_time] user_data["msg_data"] = msg_data return False msg_data = filter(lambda x: x > liimt_time, msg_data) if len(list(msg_data)) < num: user_data["msg_data"] = list(msg_data) return False return True
def filter(self, message): time = get_chat_data(message.chat_id).get(ChatData.LOCKTIME) if not time: return False if message.date.timestamp() < time: return True return False
def filter(self, message): if not message.text: return False if not check_ban_state(message.chat_id, BanMessageType.BANWORD): return False chat_data: dict = get_chat_data(chat_id=message.chat_id) re = chat_data.get(ChatData.BANWORD_RE) if not re: return False return re.search(message.text)
def filter(self, message): if not check_ban_state(message.chat_id, BanMessageType.LANG): return False chat_data: dict = get_chat_data(chat_id=message.chat_id) ban_list = chat_data.get(ChatData.LANG, []) if not len(ban_list): return False try: ret = detect(message.text) in ban_list except Exception: return False return ret
def save_data(bot=None, job=None): user_data = get_user_data() chat_data = get_chat_data() with open(CHAT_DATA_FILE, 'wb+') as f: pickle.dump(chat_data, f) with open(USER_DATA_FILE, 'wb+') as f: pickle.dump(user_data, f) if job: if isinstance(job, JobQueue): save_jobs(job) else: save_jobs(job.job_queue) logging.info("save data ok")
def filter(self, message): if not check_ban_state(message.chat_id, BanMessageType.MAXMSG): return False chat_data: dict = get_chat_data(chat_id=message.chat_id) if not chat_data.get(ChatData.MAXFLOOD): return False user_data = get_user_data(message.from_user.id) if not user_data.get(UserData.MAXMSG_DATA): user_data[UserData.MAXMSG_DATA] = {} msg_data = user_data[UserData.MAXMSG_DATA].get(message.date.day, []) if len(msg_data) >= chat_data.get(ChatData.MAXFLOOD): return True msg_data.append(1) user_data[UserData.MAXMSG_DATA][message.date.day] = msg_data return False
def filter(self, message): chat_data = get_chat_data(message.chat_id) time_start: datetime = chat_data.get(ChatData.AUTO_LOOK_START) time_stop: datetime = chat_data.get(ChatData.AUTO_LOOK_STOP) if not time_start or not time_stop: return False if message.date.hour < time_start.hour or message.date.hour > time_stop.hour: return False if time_start.hour < message.date.hour < time_stop.hour: return True if message.date.hour == time_start.hour and message.date.minute > time_start.minute: return True if message.date.hour == time_stop.hour and message.date.minute < time_stop.minute: return True return False
def filter(self, message): chat_data = get_chat_data(message.chat_id) return chat_data.get(ChatData.RUN)