Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify modq and post bots to take sub name as input #51

Merged
merged 1 commit into from
Jan 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/nasamodqbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import praw
import prawcore
from discord_webhook import DiscordWebhook
from nasautils.utilities import get_sub

try:
from q_signals import Q_WHITE, send_signal # type: ignore
Expand All @@ -17,7 +18,7 @@
except ModuleNotFoundError:
GOT_Q = False

SUB = "nasa"
SUB = get_sub()


def main():
Expand All @@ -42,7 +43,7 @@ def main():
logger.addHandler(handler)

subreddit = reddit.subreddit(SUB)
logging.info("Entering main loop")
logging.info("Entering main loop for r/%s", SUB)

for submission in subreddit.mod.stream.modqueue():
try:
Expand All @@ -51,11 +52,11 @@ def main():
title = f"Comment on post '{submission.link_title}'"
link = f"https://reddit.com{submission.permalink}"
logging.info(
"New modqueue entry from %s: %s (%s)", submission.author, title, link
"New modqueue entry in r/%s from %s: %s (%s)", SUB, submission.author, title, link
)
webhook = DiscordWebhook(
discord_webhook,
username="NASA Modqueue Bot",
username=f"{SUB} Modqueue Bot",
content=f"Modqueue: [{title} by {submission.author}]({link})",
)
webhook.execute()
Expand Down
9 changes: 5 additions & 4 deletions src/nasapostbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
import praw
import prawcore
from discord_webhook import DiscordWebhook
from nasautils.utilities import get_sub


SUB = "nasa"
SUB = get_sub()


def main():
Expand All @@ -34,15 +35,15 @@ def main():
logger.addHandler(handler)

subreddit = reddit.subreddit(SUB)
logging.info("Entering main loop")
logging.info("Entering main loop for r/%s", SUB)
for submission in subreddit.stream.submissions(skip_existing=True):
reddit_url = "https://reddit.com" + submission.permalink
logging.info(
"New post by %s: %s (%s)", submission.author, submission.title, reddit_url
"New post in r/%s by %s: %s (%s)", SUB, submission.author, submission.title, reddit_url
)
webhook = DiscordWebhook(
discord_webhook,
username="nasapostbot",
username=f"{SUB} Post Bot",
content=f"[{submission.title}]({reddit_url})",
)
webhook.execute()
Expand Down
15 changes: 15 additions & 0 deletions src/nasautils/utilities.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/python3

"""Misc utilities for r/nasa bot"""

import sys


def get_sub():
"""Get and return subreddit name"""
if len(sys.argv) != 2:
sub = 'nasa'
else:
sub = sys.argv[1:][0].lower()

return sub
Loading