From 0b516fb1ed4f9cbedb595d7182f66607e8ca8f0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Y=2E=20Eren=20Bekta=C5=9F?= Date: Thu, 25 Aug 2022 12:53:50 +0300 Subject: [PATCH 1/8] Slack Ping For Transcripts on Tor Posts This sends a message to #general channel on Slack when a transcriber posts a transcription under a ToR post. --- tor/core/inbox.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tor/core/inbox.py b/tor/core/inbox.py index b7e7a8e..20655fb 100644 --- a/tor/core/inbox.py +++ b/tor/core/inbox.py @@ -39,6 +39,14 @@ log = logging.getLogger(__name__) +THINK_EMOTES = [ + ":thinking_party:", + ":think-rotate:", + ":monoclethink:", + ":eggplant-think:", + ":thinking-screensaver:" +] + def extract_sub_from_url(url: str) -> str: """returns the sub name from the given url without "r/" at the start.""" @@ -73,10 +81,21 @@ def process_reply(reply: Comment, cfg: Config) -> None: if "image transcription" in r_body or is_comment_transcription(reply, cfg): post_link = reply.submission.url sub_name = extract_sub_from_url(post_link) + user_url = i18n["urls"]["reddit_url"].format(f"/u/{username}") + post_url = i18n["urls"]["reddit_url"].format(context) + tor_post = submission.tor_url + emote = random.choice(THINK_EMOTES) message = i18n["responses"]["general"]["transcript_on_tor_post"].format( sub_name=sub_name, post_link=post_link, ) + send_to_modchat( + f"<{user_url}|u/{username}> posted a " + f"<{post_url}|transcription> on " + f"<{tor_post}|ToR post> instead of posting it on " + f"<{post_link}|r/{sub_name}>. {emote}" + cfg, + ) elif matches := [ match.group() for match in [regex.search(reply.body) for regex in MOD_SUPPORT_PHRASES] From 1573475476c7af73d1d8a87b8d8281ead76ddff9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Y=2E=20Eren=20Bekta=C5=9F?= Date: Thu, 25 Aug 2022 13:59:33 +0300 Subject: [PATCH 2/8] moving message to localization file --- tor/core/inbox.py | 21 +++++++-------------- tor/strings/en_US.yml | 2 ++ 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/tor/core/inbox.py b/tor/core/inbox.py index 20655fb..2561380 100644 --- a/tor/core/inbox.py +++ b/tor/core/inbox.py @@ -39,14 +39,6 @@ log = logging.getLogger(__name__) -THINK_EMOTES = [ - ":thinking_party:", - ":think-rotate:", - ":monoclethink:", - ":eggplant-think:", - ":thinking-screensaver:" -] - def extract_sub_from_url(url: str) -> str: """returns the sub name from the given url without "r/" at the start.""" @@ -84,18 +76,19 @@ def process_reply(reply: Comment, cfg: Config) -> None: user_url = i18n["urls"]["reddit_url"].format(f"/u/{username}") post_url = i18n["urls"]["reddit_url"].format(context) tor_post = submission.tor_url - emote = random.choice(THINK_EMOTES) message = i18n["responses"]["general"]["transcript_on_tor_post"].format( sub_name=sub_name, post_link=post_link, ) send_to_modchat( - f"<{user_url}|u/{username}> posted a " - f"<{post_url}|transcription> on " - f"<{tor_post}|ToR post> instead of posting it on " - f"<{post_link}|r/{sub_name}>. {emote}" - cfg, + message = i18n["mod"]["transcript_on_tor_post"].format( + user_url=user_url, + post_url=post_url, + tor_post=tor_post, + sub_name=sub_name, + post_link=post_link ) + ) elif matches := [ match.group() for match in [regex.search(reply.body) for regex in MOD_SUPPORT_PHRASES] diff --git a/tor/strings/en_US.yml b/tor/strings/en_US.yml index 7df7181..6ca037c 100644 --- a/tor/strings/en_US.yml +++ b/tor/strings/en_US.yml @@ -17,6 +17,8 @@ mod: formatting_issues: | I detected formatting issues in the transcription by {author}: {issues} {link} + transcript_on_tor_post: | + Looks like {user_url} posted a [transcription]({post_url}) on [ToR Post]({tor_post}) instead of posting it on [r/{sub_name}]({post_link}). :facepalm: posts: discovered_submit_title: | {sub} | {type} | "{title}" From 8fbd17591a5fa5179ccf525843aa6992a4ae3e26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Y=2E=20Eren=20Bekta=C5=9F?= Date: Thu, 25 Aug 2022 14:05:02 +0300 Subject: [PATCH 3/8] fix2 --- tor/core/inbox.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tor/core/inbox.py b/tor/core/inbox.py index 2561380..3ea4977 100644 --- a/tor/core/inbox.py +++ b/tor/core/inbox.py @@ -72,6 +72,8 @@ def process_reply(reply: Comment, cfg: Config) -> None: if "image transcription" in r_body or is_comment_transcription(reply, cfg): post_link = reply.submission.url + submission = reply.submission + username = reply.author.name sub_name = extract_sub_from_url(post_link) user_url = i18n["urls"]["reddit_url"].format(f"/u/{username}") post_url = i18n["urls"]["reddit_url"].format(context) From 15887b9e1d4dbdf2c4ea1e406cb97f114a7a3a81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Y=2E=20Eren=20Bekta=C5=9F?= Date: Thu, 25 Aug 2022 14:10:59 +0300 Subject: [PATCH 4/8] last fix hopefully fingers crossed --- tor/core/inbox.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tor/core/inbox.py b/tor/core/inbox.py index 3ea4977..4ba43cd 100644 --- a/tor/core/inbox.py +++ b/tor/core/inbox.py @@ -63,7 +63,7 @@ def forward_to_slack(item: InboxableMixin, cfg: Config) -> None: @beeline.traced(name="process_reply") -def process_reply(reply: Comment, cfg: Config) -> None: +def process_reply(reply: Comment, context: str, cfg: Config) -> None: try: log.debug(f"Received reply from {reply.author.name}: {reply.body}") message: Optional[str] = "" From d4f017fbe33a3fc3da64e61a7c115989fd56beae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Y=2E=20Eren=20Bekta=C5=9F?= Date: Thu, 25 Aug 2022 14:18:58 +0300 Subject: [PATCH 5/8] fix for post_url --- tor/core/inbox.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tor/core/inbox.py b/tor/core/inbox.py index 4ba43cd..1a28db0 100644 --- a/tor/core/inbox.py +++ b/tor/core/inbox.py @@ -76,7 +76,7 @@ def process_reply(reply: Comment, context: str, cfg: Config) -> None: username = reply.author.name sub_name = extract_sub_from_url(post_link) user_url = i18n["urls"]["reddit_url"].format(f"/u/{username}") - post_url = i18n["urls"]["reddit_url"].format(context) + post_url = submission.url tor_post = submission.tor_url message = i18n["responses"]["general"]["transcript_on_tor_post"].format( sub_name=sub_name, From 1463158f51e80f323e0c31ced45c84e61e2a4ca4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Y=2E=20Eren=20Bekta=C5=9F?= Date: Thu, 25 Aug 2022 14:21:59 +0300 Subject: [PATCH 6/8] fix for post_url 2 --- tor/core/inbox.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tor/core/inbox.py b/tor/core/inbox.py index 1a28db0..e547a6f 100644 --- a/tor/core/inbox.py +++ b/tor/core/inbox.py @@ -63,7 +63,7 @@ def forward_to_slack(item: InboxableMixin, cfg: Config) -> None: @beeline.traced(name="process_reply") -def process_reply(reply: Comment, context: str, cfg: Config) -> None: +def process_reply(reply: Comment, cfg: Config) -> None: try: log.debug(f"Received reply from {reply.author.name}: {reply.body}") message: Optional[str] = "" From 442eb987696054e295ba94a1b45530ac4d33a592 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Y=2E=20Eren=20Bekta=C5=9F?= Date: Thu, 25 Aug 2022 14:24:31 +0300 Subject: [PATCH 7/8] fix for post_url 3 --- tor/core/inbox.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tor/core/inbox.py b/tor/core/inbox.py index e547a6f..32adbc9 100644 --- a/tor/core/inbox.py +++ b/tor/core/inbox.py @@ -83,7 +83,7 @@ def process_reply(reply: Comment, cfg: Config) -> None: post_link=post_link, ) send_to_modchat( - message = i18n["mod"]["transcript_on_tor_post"].format( + i18n["mod"]["transcript_on_tor_post"].format( user_url=user_url, post_url=post_url, tor_post=tor_post, From 4ca275a87ec022c074c9e2f924df7314cf73417f Mon Sep 17 00:00:00 2001 From: Joe Kaufeld Date: Sun, 28 Aug 2022 15:42:54 -0400 Subject: [PATCH 8/8] clean up type hinting and add additional context --- tor/core/inbox.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/tor/core/inbox.py b/tor/core/inbox.py index 32adbc9..103708e 100644 --- a/tor/core/inbox.py +++ b/tor/core/inbox.py @@ -4,8 +4,7 @@ import beeline from praw.exceptions import ClientException -from praw.models import Comment, Message -from praw.models.reddit.mixins import InboxableMixin +from praw.models import Comment, Message, Submission from tor import __BOT_NAMES__ from tor.core import ( @@ -46,7 +45,7 @@ def extract_sub_from_url(url: str) -> str: @beeline.traced(name="forward_to_slack") -def forward_to_slack(item: InboxableMixin, cfg: Config) -> None: +def forward_to_slack(item: Comment, cfg: Config) -> None: username = str(item.author.name) send_to_modchat( @@ -71,13 +70,12 @@ def process_reply(reply: Comment, cfg: Config) -> None: r_body = reply.body.lower() # cache that thing if "image transcription" in r_body or is_comment_transcription(reply, cfg): - post_link = reply.submission.url - submission = reply.submission - username = reply.author.name - sub_name = extract_sub_from_url(post_link) - user_url = i18n["urls"]["reddit_url"].format(f"/u/{username}") - post_url = submission.url - tor_post = submission.tor_url + post_link: str = reply.submission.url + tor_submission: Submission = reply.submission + username: str = reply.author.name + sub_name: str = extract_sub_from_url(post_link) + user_url: str = i18n["urls"]["reddit_url"].format(f"/u/{username}") + linked_submission: Submission = cfg.r.submission(url=tor_submission.url) message = i18n["responses"]["general"]["transcript_on_tor_post"].format( sub_name=sub_name, post_link=post_link, @@ -198,7 +196,7 @@ def check_inbox(cfg: Config) -> None: :return: None. """ # Sort inbox, then act on it - # Invert the inbox so we're processing oldest first! + # Invert the inbox so that we're processing the oldest first! for item in reversed(list(cfg.r.inbox.unread(limit=None))): # Very rarely we may actually get a message from Reddit itself. # In this case, there will be no author attribute.