From 71d27f517622d38e5df2d9220e58d18d8b1332bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian-Samuel=20Geb=C3=BChr?= Date: Wed, 14 Dec 2022 17:56:26 +0100 Subject: [PATCH] Add fix #2 --- CHANGELOG.md | 5 +++++ alertbot.py | 7 ++++++- maubot.yaml | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e2a604c..e3ab7bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# December 2022 + +* Handle sending an alert to a room where the bot is not allowed to send messages [#2](https://github.com/moan0s/alertbot/issues/2) +* Add [uptime-kuma](https://github.com/louislam/uptime-kuma) resolved message with proper formatting + # September 2022 * Add [uptime-kuma](https://github.com/louislam/uptime-kuma) example \ No newline at end of file diff --git a/alertbot.py b/alertbot.py index b946e05..1a5791b 100644 --- a/alertbot.py +++ b/alertbot.py @@ -3,6 +3,7 @@ from maubot.handlers import web, command from aiohttp.web import Request, Response, json_response import json import datetime +from mautrix.errors.request import MForbidden helpstring = f"""# Alertbot @@ -186,7 +187,11 @@ class AlertBot(Plugin): @web.post("/webhook/{room_id}") async def webhook_room(self, req: Request) -> Response: room_id = req.match_info["room_id"].strip() - await self.send_alert(req, room=room_id) + try: + await self.send_alert(req, room=room_id) + except MForbidden: + self.log.error(f"Could not send to {room_id}: Forbidden. Most likely the bot is not invited in the room.") + return json_response('{"status": "forbidden", "error": "forbidden"}', status=403) return json_response({"status": "ok"}) @command.new() diff --git a/maubot.yaml b/maubot.yaml index e9d605a..d4dd2d4 100644 --- a/maubot.yaml +++ b/maubot.yaml @@ -1,6 +1,6 @@ maubot: 0.1.0 id: de.hyteck.alertbot -version: 1.1.0 +version: 1.1.1 license: AGPL-3.0-or-later modules: - alertbot