Skip to content

Commit

Permalink
Merge pull request #4134 from dev-hato/fix_cred
Browse files Browse the repository at this point in the history
Misskey: クレデンシャル取得処理を一回だけ行う
  • Loading branch information
nakkaa authored Jul 5, 2024
2 parents 5179b38 + c5e1467 commit fe42ea7
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,17 @@ def main():
elif conf.MODE == "misskey":
misskey_client = Misskey(conf.MISSKEY_DOMAIN, i=conf.MISSKEY_API_TOKEN)

for i in range(10):
try:
cred = misskey_client.i()
break
except ReadTimeout as e:
if i < 9:
logger.exception(e)
time.sleep(1)
else:
raise e

async def misskey_runner():
while True:
try:
Expand Down Expand Up @@ -222,30 +233,21 @@ async def misskey_runner():
host = note["user"].get("host")
mentions = note.get("mentions")
if (
host is None or host == conf.MISSKEY_DOMAIN
) and mentions:
cred = None

for i in range(10):
try:
cred = misskey_client.i()
break
except ReadTimeout as e:
logger.exception(e)
time.sleep(1)

if cred is not None and cred["id"] in mentions:
client = MisskeyClient(misskey_client, note)
client.add_waiting_reaction()
try:
analyze.analyze_message(
note["text"]
.replace("\xa0", " ")
.split(" ", 1)[1]
)(client)
except Exception as e:
logger.exception(e)
client.post("エラーが発生したっぽ......")
(host is None or host == conf.MISSKEY_DOMAIN)
and mentions
and cred["id"] in mentions
):
client = MisskeyClient(misskey_client, note)
client.add_waiting_reaction()
try:
analyze.analyze_message(
note["text"]
.replace("\xa0", " ")
.split(" ", 1)[1]
)(client)
except Exception as e:
logger.exception(e)
client.post("エラーが発生したっぽ......")
except websockets.ConnectionClosedError:
time.sleep(1)

Expand Down

0 comments on commit fe42ea7

Please sign in to comment.