From f1656ff9331f18cbebcb71e85ad4677b26f40e65 Mon Sep 17 00:00:00 2001 From: Mint <> Date: Mon, 6 Mar 2023 02:27:13 +0300 Subject: [PATCH] Handle exceptions with malformed reply command --- reply.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/reply.py b/reply.py index 0d815c4..440f486 100755 --- a/reply.py +++ b/reply.py @@ -77,15 +77,19 @@ class ReplyBot: if command in ('pin', 'unpin'): await (self.pleroma.pin if command == 'pin' else self.pleroma.unpin)(target_post_id) elif command == 'reply': - status = await self.pleroma.get_status(argument) - if status['content'] != "": - keywords = cleanup_toot(utils.extract_post_content(status['content']), self.cfg) - else: - keywords = None + try: + status = await self.pleroma.get_status(argument) + if status['content'] != "": + keywords = cleanup_toot(utils.extract_post_content(status['content']), self.cfg) + else: + keywords = None - toot = await utils.make_post(self.cfg, keywords) - toot = self.cleanup_toot(toot, self.cfg) - await self.pleroma.reply(status, toot, cw=self.cfg['cw']) + toot = await utils.make_post(self.cfg, keywords) + toot = self.cleanup_toot(toot, self.cfg) + await self.pleroma.reply(status, toot, cw=self.cfg['cw']) + except: + tg.start_soon(self.pleroma.react, post_id, '❌') + tg.start_soon(self.pleroma.reply, notification['status'], 'Error: ' + exc.args[0]) except pleroma.BadRequest as exc: async with anyio.create_task_group() as tg: tg.start_soon(self.pleroma.react, post_id, '❌')