Skip to content

Commit

Permalink
Merge pull request #86 from akrherz/gh85_x_errors
Browse files Browse the repository at this point in the history
Implement some error handling logic
  • Loading branch information
akrherz authored Jul 10, 2024
2 parents bfb0691 + 0fe742a commit f848b60
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ci:
autoupdate_schedule: quarterly
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.5.0"
rev: "v0.5.1"
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down
16 changes: 10 additions & 6 deletions src/iembot/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
import iembot

TWEET_API = "https://api.twitter.com/2/tweets"
# 89: Expired token, so we shall revoke for now
# 185: User is over quota
# 226: Twitter thinks this tweeting user is spammy, le sigh
# 326: User is temporarily locked out
# 64: User is suspended
DISABLE_TWITTER_CODES = [89, 185, 226, 326, 64]


def tweet(bot, user_id, twttxt, **kwargs):
Expand Down Expand Up @@ -87,6 +93,9 @@ def _helper(params):
# 185: Over quota
# 187: duplicate tweet
return None
if errcode in DISABLE_TWITTER_CODES:
disable_twitter_user(bot, user_id, errcode)
return None

# Something bad happened with submitting this to twitter
if str(exp).startswith("media type unrecognized"):
Expand Down Expand Up @@ -433,12 +442,7 @@ def twitter_errback(err, bot, user_id, tweettext):
# Always log it
log.err(err)
errcode = twittererror_exp_to_code(err)
if errcode in [89, 185, 226, 326, 64]:
# 89: Expired token, so we shall revoke for now
# 185: User is over quota
# 226: Twitter thinks this tweeting user is spammy, le sigh
# 326: User is temporarily locked out
# 64: User is suspended
if errcode in DISABLE_TWITTER_CODES:
disable_twitter_user(bot, user_id, errcode)
else:
sn = bot.tw_users.get(user_id, {}).get("screen_name", "")
Expand Down

0 comments on commit f848b60

Please sign in to comment.