Exemplo n.º 1
0
async def edit_entry(
	title, content, editor=None, unlisted=False, entry_id=None, image=None, editor_real=None, impersonate=None
):
	t = datetime.now()
	title = title.strip()
	await discordbot.log_edit(editor, title, t)
	content = utils.fix_html(content)
	nohtml_content = utils.remove_html(content)
	new_data = {'title': title, 'content': content, 'last_edited': t, 'nohtml_content': nohtml_content}
	if unlisted is not None:
		new_data['unlisted'] = unlisted
	if image is not None:
		new_data['image'] = {'src': image}
	
	new_data['edited_by_minx'] = editor == 359017688867012628
	
	if not entry_id:
		entry_id = str(uuid.uuid4())
	new_history_data = {
		'author': editor,
		'content': content,
		'title': title,
		'time': t,
		'unlisted': unlisted,
	}
	if image is not None:
		new_history_data['image'] = {'src': image}
	await entries_coll.update_one({'_id': entry_id}, {'$set': new_data, '$push': {'history': new_history_data}}, upsert=True)
	return entry_id
Exemplo n.º 2
0
async def fix_entry(data):
	if data is None:
		return
	original_data = dict(data)
	if data.get('image') and isinstance(data['image'], str):
		data['image'] = data['image'].replace('imag.cf', 'i.matdoes.dev')
	if data.get('image') and isinstance(data.get('image'), str):
		data['image'] = await images.get_data(data['image'])
	elif data.get('image') and not data['image'].get('thumbnail_b64'):
		data['image'] = await images.get_data(data['image']['src'])
	if data != original_data:
		await entries_coll.update_one({'_id': data['_id']}, {'$set': data})
	data['content'] = utils.fix_html(data['content'])
	if 'nohtml_content' not in data:
		data['nohtml_content'] = utils.remove_html(data['content'])
	return data
Exemplo n.º 3
0
async def edit_entry(
	title: str,
	content: str,
	editor_id: int,
	unlisted: bool = False,
	entry_id: str = None,
	image: str = None
):
	t = datetime.now()
	title = title.strip()
	await discordbot.log_edit(editor_id, title)
	content = utils.fix_html(content)
	nohtml_content = utils.remove_html(content)
	new_data: PartialDatabaseEntry = {
		'title': title,
		'content': content,
		'last_edited': t,
		'nohtml_content': nohtml_content,
		'unlisted': unlisted or False
	}
	if image is not None:
		new_data['image'] = await images.get_data(image)

	if not entry_id:
		entry_id = str(uuid.uuid4())
	new_history_data: DatabaseHistoryItem = {
		'author': editor_id,
		'content': content,
		'title': title,
		'time': t,
		'unlisted': unlisted,
		'image': None
	}
	if image is not None:
		new_history_data['image'] = {
			'src': image,
			'thumbnail_b64': None,
			'thumbnail_content_type': None
		}

	await entries_coll.update_one({'_id': entry_id}, {'$set': new_data, '$push': {'history': new_history_data}}, upsert=True)
	return entry_id