Skip to content

Instantly share code, notes, and snippets.

@jb3
Created July 14, 2020 22:57
Show Gist options
  • Save jb3/7718479566a2506ae81f80ba9041f664 to your computer and use it in GitHub Desktop.
Save jb3/7718479566a2506ae81f80ba9041f664 to your computer and use it in GitHub Desktop.
Reddit report to Discord relay
import httpx
from praw import Reddit
from praw.models import Comment, Submission
from datetime import datetime
r = Reddit(
client_id="",
client_secret="",
password="",
user_agent="pythonmodqueuerelay by /u/Im__Joseph",
username="",
)
WEBHOOK_URL = ""
SUBREDDIT = "Python"
for submission in r.subreddit(SUBREDDIT).mod.stream.reports():
data = None
if isinstance(submission, Comment):
data = {
"embeds": [
{
"title": "New comment report",
"description": submission.body[:1900],
"color": 13914449,
"timestamp": datetime.utcnow().isoformat(),
"url": "https://reddit.com" + submission.permalink,
"author": {
"name": f"/u/{submission.author.name}",
"url": f"https://reddit.com/u/{submission.author.name}",
"icon_url": submission.author.icon_img
},
"fields": [
{
"name": report[0],
"value": f"{report[1]} report" + ("s" if report[1] != 1 else "")
}
for report in submission.user_reports
],
}
],
"username": "/r/Python",
"avatar_url": "https://cdn3.iconfinder.com/data/icons/2018-social-media-logotypes/1000/2018_social_media_popular_app_logo_reddit-512.png"
}
elif isinstance(submission, Submission):
data = {
"embeds": [
{
"title": "New post report",
"description": submission.title,
"color": 13914449,
"timestamp": datetime.utcnow().isoformat(),
"url": "https://reddit.com" + submission.permalink,
"author": {
"name": f"/u/{submission.author.name}",
"url": f"https://reddit.com/u/{submission.author.name}",
"icon_url": submission.author.icon_img
},
"fields": [
{
"name": report[0],
"value": f"{report[1]} report" + ("s" if report[1] != 1 else "")
}
for report in submission.user_reports
],
}
],
"username": "/r/Python",
"avatar_url": "https://cdn3.iconfinder.com/data/icons/2018-social-media-logotypes/1000/2018_social_media_popular_app_logo_reddit-512.png"
}
if data:
resp = httpx.post(
WEBHOOK_URL,
json=data,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment