async def create_response(entry_data, preview=False): if entry_data: entry_id = entry_data['_id'] title = entry_data['title'] content = entry_data.get('content', '[no content]') unlisted = entry_data.get('unlisted', False) image = entry_data.get('image') markdown = entry_data.get('markdown') no_html = entry_data.get('nohtml_content') content = await utils.before_show_text(content) markdown = utils.html_to_markdown(content) owner_id = entry_data.get('owner_id') else: return web.HTTPNotFound() url_title = utils.url_title(title) if preview: return {'title': title, 'preview': utils.remove_html(content), 'html': content, 'id': entry_id, 'image': image} else: return { 'slug': url_title, 'id': entry_id, 'title': title, 'html': content, 'unlisted': unlisted, 'image': image, 'markdown': markdown, 'no_html': no_html, 'owner_id': owner_id, }
async def create_entry_embed(entry_data, author_id=None, raw_entry=False): if not raw_entry: html = entry_data['content'] content = utils.html_to_markdown(html) content_ending = '' if len(content) > 2048: content = content[:2045 - len(content_ending)] + '...' content += content_ending title = utils.url_title(entry_data['title']) view_url = f'{BASE_URL}/entry/{title}' view_url = view_url embed = discord.Embed(title=entry_data['title'], description=content, url=view_url) if entry_data.get('image'): embed.set_thumbnail(url=entry_data['image']['src']) return embed else: entry_data = dict(entry_data) content = entry_data['nohtml_content'] content_ending = '' if len(content) > 1024: content = content[:1021 - len(content_ending)] + '...' try: del entry_data['image'] except KeyError: pass entry_data['nohtml_content'] = content del entry_data['content'] del entry_data['history'] return utils.embed_from_dict(entry_data, color=0x00FF00, title='raw entry data')