async def update_handlers_cache(chat_id): redis.delete(f'filters_cache_{chat_id}') filters = db.filters.find({'chat_id': chat_id}) handlers = [] async for filter in filters: handler = filter['handler'] if handler in handlers: continue handlers.append(handler) redis.lpush(f'filters_cache_{chat_id}', handler) return handlers
async def set_connected_chat(user_id, chat_id): key = f'connection_cache_{user_id}' redis.delete(key) if not chat_id: await db.connections.update_one({'user_id': user_id}, {"$unset": {'chat_id': 1}}, upsert=True) return return await db.connections.update_one( {'user_id': user_id}, { "$set": {'user_id': user_id, 'chat_id': chat_id}, "$addToSet": {'history': {'$each': [chat_id]}} }, upsert=True )
user_id = message.from_user.id note_name = cached['notename'] note = await db.notes_v2.find_one({ 'chat_id': chat_id, 'names': { '$in': [note_name] } }) await get_note(message, db_item=note, chat_id=chat_id, send_id=user_id, rpl_id=None) redis.delete(key) async def __stats__(): text = "* <code>{}</code> total notes\n".format( await db.notes_v2.count_documents({})) return text async def __export__(chat_id): data = [] notes = await db.notes_v2.find({ 'chat_id': chat_id }).sort("names", 1).to_list(length=300) for note in notes: del note['_id']
async def connected_start_state(message, strings, chat): key = 'sophie_connected_start_state:' + str(message.from_user.id) if redis.get(key): await message.reply(strings['pm_connected'].format(chat_name=chat['chat_title'])) redis.delete(key)