Add crosspost support to reddit commands

This commit is contained in:
Zeva Rose 2022-05-05 00:24:47 -06:00
parent 828ea92188
commit 4599bd31bd

View file

@ -50,6 +50,7 @@ class RedditCog(Cog):
url = "https://reddit.com" + post.permalink
await post.author.load()
author_url = f"https://reddit.com/u/{post.author.name}"
author_icon = post.author.icon_img
images = []
title = f"{post.title}"
fields = []
@ -57,9 +58,10 @@ class RedditCog(Cog):
og_post = None
if not post.is_self:
og_post = post # noqa: F841
post = await self.api.submission(post.crosspost_parents_list[0]["id"])
post = await self.api.submission(post.crosspost_parent_list[0]["id"])
await post.load()
fields.append(EmbedField(name="Crossposted From", value=post.subreddit_name_prefixed))
content = f"> **{post.title}**\n\n"
content = f"> **{post.title}**"
if "url" in vars(post):
if any(post.url.endswith(x) for x in ["jpeg", "jpg", "png", "gif"]):
images = [post.url]
@ -74,7 +76,7 @@ class RedditCog(Cog):
break
if "selftext" in vars(post) and post.selftext:
content += post.selftext
content += "\n\n" + post.selftext
if len(content) > 900:
content = content[:900] + "..."
content += f"\n\n[View this post]({url})"
@ -89,13 +91,13 @@ class RedditCog(Cog):
base_embed = build_embed(
title=title,
description=content,
fields=[],
fields=fields,
timestamp=post.created_utc,
url=url,
color=color,
)
base_embed.set_author(
name="u/" + post.author.name, url=author_url, icon_url=post.author.icon_img
name="u/" + post.author.name, url=author_url, icon_url=author_icon
)
base_embed.set_footer(
text="Reddit", icon_url="https://www.redditinc.com/assets/images/site/reddit-logo.png"
@ -399,7 +401,7 @@ class RedditCog(Cog):
async def _reddit_post(self, ctx: InteractionContext, sid: str) -> None:
await ctx.defer()
try:
post = await self.api.submission(sid)()
post = await self.api.submission(sid)
await post.load()
except (NotFound, Forbidden, Redirect) as e:
self.logger.debug(f"Submission {sid} raised {e.__class__.__name__} in post")