From 4599bd31bd8c013b74479621299a514d936eef73 Mon Sep 17 00:00:00 2001 From: Zevaryx Date: Thu, 5 May 2022 00:24:47 -0600 Subject: [PATCH] Add crosspost support to reddit commands --- jarvis/cogs/reddit.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/jarvis/cogs/reddit.py b/jarvis/cogs/reddit.py index 2f6a900..f292f78 100644 --- a/jarvis/cogs/reddit.py +++ b/jarvis/cogs/reddit.py @@ -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")