diff --git a/jarvis/cogs/reddit.py b/jarvis/cogs/reddit.py index b9a52f0..eb148f7 100644 --- a/jarvis/cogs/reddit.py +++ b/jarvis/cogs/reddit.py @@ -247,13 +247,13 @@ class RedditCog(Scale): await ctx.send("Subreddit may be private, quarantined, or nonexistent.", ephemeral=True) return try: - hot = [x async for x in subreddit.hot(limit=1)][0] + post = [x async for x in subreddit.hot(limit=1)][0] except Exception as e: - self.logger.error(f"Failed to get hot from {name}", exc_info=e) + self.logger.error(f"Failed to get post from {name}", exc_info=e) await ctx.send("Well, this is awkward. Something went wrong", ephemeral=True) return - embeds = await self.post_embeds(subreddit, hot) + embeds = await self.post_embeds(subreddit, post) await ctx.send(embeds=embeds) @reddit.subcommand(sub_cmd_name="top", sub_cmd_description="Get the top post of a subreddit") @@ -287,13 +287,13 @@ class RedditCog(Scale): await ctx.send("Subreddit may be private, quarantined, or nonexistent.", ephemeral=True) return try: - hot = [x async for x in subreddit.top(time_filter=time, limit=1)][0] + post = [x async for x in subreddit.top(time_filter=time, limit=1)][0] except Exception as e: - self.logger.error(f"Failed to get hot from {name}", exc_info=e) + self.logger.error(f"Failed to get post from {name}", exc_info=e) await ctx.send("Well, this is awkward. Something went wrong", ephemeral=True) return - embeds = await self.post_embeds(subreddit, hot) + embeds = await self.post_embeds(subreddit, post) await ctx.send(embeds=embeds) @reddit.subcommand( @@ -316,13 +316,42 @@ class RedditCog(Scale): await ctx.send("Subreddit may be private, quarantined, or nonexistent.", ephemeral=True) return try: - hot = await subreddit.random() + post = await subreddit.random() except Exception as e: - self.logger.error(f"Failed to get hot from {name}", exc_info=e) + self.logger.error(f"Failed to get post from {name}", exc_info=e) await ctx.send("Well, this is awkward. Something went wrong", ephemeral=True) return - embeds = await self.post_embeds(subreddit, hot) + embeds = await self.post_embeds(subreddit, post) + await ctx.send(embeds=embeds) + + @reddit.subcommand( + sub_cmd_name="rising", sub_cmd_description="Get a rising post of a subreddit" + ) + @slash_option( + name="name", description="Subreddit name", opt_type=OptionTypes.STRING, required=True + ) + async def _subreddit_rising(self, ctx: InteractionContext, name: str) -> None: + await ctx.defer() + name = name.replace("r/", "") + if len(name) > 20 or len(name) < 3: + await ctx.send("Invalid Subreddit name", ephemeral=True) + return + try: + subreddit = await self.api.subreddit(name) + await subreddit.load() + except (NotFound, Forbidden, Redirect) as e: + self.logger.debug(f"Subreddit {name} raised {e.__class__.__name__} in rising") + await ctx.send("Subreddit may be private, quarantined, or nonexistent.", ephemeral=True) + return + try: + post = [x async for x in subreddit.rising(limit=1)][0] + except Exception as e: + self.logger.error(f"Failed to get post from {name}", exc_info=e) + await ctx.send("Well, this is awkward. Something went wrong", ephemeral=True) + return + + embeds = await self.post_embeds(subreddit, post) await ctx.send(embeds=embeds)