Skip to content

Commit

Permalink
Merge pull request #92 from akrherz/robust
Browse files Browse the repository at this point in the history
Robustness, hopefully
  • Loading branch information
akrherz authored Nov 11, 2024
2 parents c005233 + 6f1f58b commit 0418565
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ ci:
autoupdate_schedule: quarterly
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.7.2"
rev: "v0.7.3"
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format

- repo: https://github.com/tox-dev/pyproject-fmt
rev: '2.4.3'
rev: 'v2.5.0'
hooks:
- id: pyproject-fmt
29 changes: 21 additions & 8 deletions src/iembot/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,16 @@ def at_send_message(bot, user_id, msg: str, **kwargs):
log.err(exp)

if at_handle not in bot.at_clients:
bot.at_clients[at_handle] = atproto.Client()
bot.at_clients[at_handle].login(
# This is racey, so we need to not add the client until we are
# sure it is logged in
client = atproto.Client()
client.login(
at_handle,
bot.tw_users[user_id]["at_app_pass"],
)
# Again, racey, so we need to check again
if at_handle not in bot.at_clients:
bot.at_clients[at_handle] = client

if msg.find("http") > -1:
parts = msg.split("http")
Expand All @@ -75,12 +80,20 @@ def at_send_message(bot, user_id, msg: str, **kwargs):
.link("link", f"http{parts[1]}")
)

if img:
res = bot.at_clients[at_handle].send_image(
msg, image=img, image_alt="IEMBot Image TBD"
)
else:
res = bot.at_clients[at_handle].send_post(msg)
for attempt in range(1, 4):
try:
if img:
res = bot.at_clients[at_handle].send_image(
msg, image=img, image_alt="IEMBot Image TBD"
)
else:
res = bot.at_clients[at_handle].send_post(msg)
break
except Exception as exp:
log.err(exp)
time.sleep(attempt * 5)
if attempt == 3:
raise exp
# for now
log.msg(repr(res))
return res
Expand Down

0 comments on commit 0418565

Please sign in to comment.