diff --git a/src/nasamodqbot.py b/src/nasamodqbot.py index 283882c..7d089f4 100644 --- a/src/nasamodqbot.py +++ b/src/nasamodqbot.py @@ -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 @@ -17,7 +18,7 @@ except ModuleNotFoundError: GOT_Q = False -SUB = "nasa" +SUB = get_sub() def main(): @@ -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: @@ -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() diff --git a/src/nasapostbot.py b/src/nasapostbot.py index bee3dc1..0834cee 100644 --- a/src/nasapostbot.py +++ b/src/nasapostbot.py @@ -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(): @@ -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() diff --git a/src/nasautils/utilities.py b/src/nasautils/utilities.py new file mode 100644 index 0000000..1d83349 --- /dev/null +++ b/src/nasautils/utilities.py @@ -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