Skip to content

Commit

Permalink
Create new error tag for blocked inbox
Browse files Browse the repository at this point in the history
  • Loading branch information
rossjrw committed Jan 20, 2025
1 parent a75b74d commit 1a9939f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
21 changes: 19 additions & 2 deletions notifier/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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",
{
Expand All @@ -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()

Expand Down
10 changes: 7 additions & 3 deletions notifier/wikidot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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"]
Expand Down

0 comments on commit 1a9939f

Please sign in to comment.