async def update_admin_cache(chat_id): admin_list = await bot.get_participants( int(chat_id), filter=ChannelParticipantsAdmins()) admins = [] for admin in admin_list: admins.append(admin.id) dump = ujson.dumps(admins) redis.set('admins_cache_{}'.format(chat_id), dump) redis.expire('admins_cache_{}'.format(chat_id), 3600)
def update_locks_cache(chat_id): key = 'locks_cache_{}'.format(chat_id) redis.delete(key) data = mongodb.locks.find_one({'chat_id': chat_id}) if not data: return False for lock in data: if lock == 'chat_id' or lock == '_id': continue if data[lock] is True: redis.lpush(key, lock) redis.expire(key, 3600) return True
async def prevent_flooding(message, command): user_id = message.from_user.id if user_id in SUDO: return True key = 'antiflood_{}_{}'.format(user_id, command) num = redis.incr(key, 1) redis.incr(key, 10) if num == 10: redis.expire(key, 120) await message.reply("Aniflood limit reached, please wait 2 minutes!") elif num > 10: return False return True
async def flood_limit(event, command): if event.chat_id: chat_id = event.chat_id else: chat_id = event.from_id if not hasattr(event, 'from_id'): check = event.query.user_id else: check = event.from_id if check in SUDO: return True db_name = 'flood_command_{}_{}'.format(chat_id, command) redis.incr(db_name, 1) number = int(redis.get(db_name)) redis.expire(db_name, 60) if number > 7: return False redis.expire(db_name, 120) if number > 6: return False await event.reply( '**Flood detected!**\nPlease wait 3 minutes before do this again!') redis.expire(db_name, 120) else: return True
async def flood_limit(command, chat_id): if chat_id in SUDO: return True db_name = 'flood_command_{}_{}'.format(chat_id, command) redis.incr(db_name, 1) number = int(redis.get(db_name)) redis.expire(db_name, 60) if number > 7: return False redis.expire(db_name, 120) if number > 6: return False redis.expire(db_name, 120) else: return True