diff --git a/notifier/notify.py b/notifier/notify.py index 7a60fe06..72cb2143 100644 --- a/notifier/notify.py +++ b/notifier/notify.py @@ -25,7 +25,12 @@ EmailAddresses, LocalConfig, ) -from notifier.wikidot import Wikidot, NotLoggedIn, RestrictedInbox +from notifier.wikidot import ( + Wikidot, + NotLoggedIn, + RestrictedInbox, + BlockedInbox, +) logger = logging.getLogger(__name__) @@ -455,7 +460,7 @@ def remove_error_tags_from_user() -> None: try: wikidot.send_message(user["user_id"], subject, body) except RestrictedInbox: - # If the inbox is restricted, inform the user + # If the inbox is restricted to contacts only, inform the user logger.debug( "Aborting notification %s", { @@ -466,6 +471,18 @@ def remove_error_tags_from_user() -> None: ) add_error_tag_to_user("restricted-inbox", post_count) return False, 0 + except BlockedInbox: + # If the inbox is blocked to all users, inform the user + logger.debug( + "Aborting notification %s", + { + "for user": user["username"], + "in channel": channel, + "reason": "blocked Wikidot inbox", + }, + ) + add_error_tag_to_user("blocked-inbox", post_count) + return False, 0 # This user has fixed the above issue, so remove error tags remove_error_tags_from_user() diff --git a/notifier/wikidot.py b/notifier/wikidot.py index 7323aefe..bc993682 100644 --- a/notifier/wikidot.py +++ b/notifier/wikidot.py @@ -50,8 +50,12 @@ class ThreadNotExists(Exception): class RestrictedInbox(Exception): - """Indicates that a user could not receive a Wikidot PM because their - inbox is restricted.""" + """Indicates that a user could not receive a Wikidot PM because their inbox + is restricted to contacts only.""" + + +class BlockedInbox(Exception): + """Indicates that a user has blocked incoming PMs from all users.""" class NotLoggedIn(Exception): @@ -189,7 +193,7 @@ def module( and response["message"] == "This user does wish to receive private messages." # [sic] ): - raise RestrictedInbox + raise BlockedInbox if ( response["status"] == "no_permission" and response["message"]