def UpdateReply( self: Any, compilation: Optional[praw.reddit.Comment], reply: Optional[praw.reddit.Comment], flair: str, ) -> Optional[praw.reddit.Comment]: """Update the existing comment in the specified thread.""" try: compilation.edit( compilation.body.split(self.watermark)[0] + self.template.format( reply.permalink, reply.author.name, reply.author.name, flair, Utility.Quote(self, reply.body), ) + self.watermark ) return compilation except Exception as e: log.error( f"Failed to edit comment in /r/{compilation.subreddit.display_name}, {e}" )
def Webhook( self: Any, comment: praw.reddit.Comment, flair: str, configuration: dict ) -> None: """Send the specified comment to Discord via Webhook.""" embed: dict = { "username": configuration["name"], "avatar_url": configuration["avatarUrl"], "embeds": [ { "color": int("FF5700", base=16), "author": { "name": f"/u/{comment.author.name} ({flair})", "url": f"https://reddit.com/user/{comment.author.name}", "icon_url": comment.author.icon_img, }, "title": f"Comment in /r/{comment.subreddit.display_name}", "url": f"https://reddit.com{comment.permalink}?context=1000", "description": Utility.Truncate( self, Utility.Quote(self, comment.body), 2045 ), "footer": { "icon_url": "https://i.imgur.com/zbrkjFR.png", "text": "Snoopy", }, "timestamp": Utility.NowISO(self), } ], } res: httpx.Response = httpx.post(configuration["url"], json=embed) # HTTP 204 (Success: No Content) if (code := res.status_code) != 204: log.error(f"Failed to POST to Discord Webhook (HTTP {code}), {res.text}")
def CreateReply( self: Any, reply: Optional[praw.reddit.Comment], parent: praw.reddit.Submission, flair: str, ) -> Optional[praw.reddit.Comment]: """Create a new comment in the specified thread.""" try: compilation: Optional[praw.reddit.Comment] = parent.reply( self.template.format( reply.permalink, reply.author.name, reply.author.name, flair, Utility.Quote(self, reply.body), ) + self.watermark ) return compilation except Exception as e: log.error( f"Failed to reply to post in /r/{parent.subreddit.display_name}, {e}" )