From 43989970d50182df7f2e872ffd297940093fae47 Mon Sep 17 00:00:00 2001 From: Masaya Suzuki <15100604+massongit@users.noreply.github.com> Date: Fri, 5 Jul 2024 22:47:58 +0900 Subject: [PATCH] =?UTF-8?q?Revert=20"Misskey:=20=E3=82=AF=E3=83=AC?= =?UTF-8?q?=E3=83=87=E3=83=B3=E3=82=B7=E3=83=A3=E3=83=AB=E5=8F=96=E5=BE=97?= =?UTF-8?q?=E5=87=A6=E7=90=86=E3=82=92=E4=B8=80=E5=9B=9E=E3=81=A0=E3=81=91?= =?UTF-8?q?=E8=A1=8C=E3=81=86"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- run.py | 50 ++++++++++++++++++++++++-------------------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/run.py b/run.py index 4064c2cd5c..c583e616c5 100644 --- a/run.py +++ b/run.py @@ -194,17 +194,6 @@ def main(): misskey_client = Misskey(conf.MISSKEY_DOMAIN, i=conf.MISSKEY_API_TOKEN) misskey_client.timeout = 2 - 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: @@ -234,21 +223,30 @@ async def misskey_runner(): host = note["user"].get("host") mentions = note.get("mentions") if ( - (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("エラーが発生したっぽ......") + 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("エラーが発生したっぽ......") except websockets.ConnectionClosedError: time.sleep(1)