mirror of
https://github.com/bsedin/matrix-webhook.git
synced 2026-04-09 03:15:40 +00:00
flake8, pydocstyle, pyupgrade → ruff
This commit is contained in:
@@ -12,8 +12,7 @@ LOGGER = logging.getLogger("matrix_webhook.app")
|
||||
|
||||
|
||||
async def main(event):
|
||||
"""
|
||||
Launch main coroutine.
|
||||
"""Launch main coroutine.
|
||||
|
||||
matrix client login & start web server
|
||||
"""
|
||||
|
||||
@@ -34,7 +34,7 @@ parser.add_argument(
|
||||
),
|
||||
)
|
||||
auth = parser.add_mutually_exclusive_group(
|
||||
required=all(v not in os.environ for v in ["MATRIX_PW", "MATRIX_TOKEN"])
|
||||
required=all(v not in os.environ for v in ["MATRIX_PW", "MATRIX_TOKEN"]),
|
||||
)
|
||||
auth.add_argument(
|
||||
"-p",
|
||||
@@ -61,7 +61,11 @@ parser.add_argument(
|
||||
),
|
||||
)
|
||||
parser.add_argument(
|
||||
"-v", "--verbose", action="count", default=0, help="increment verbosity level"
|
||||
"-v",
|
||||
"--verbose",
|
||||
action="count",
|
||||
default=0,
|
||||
help="increment verbosity level",
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
@@ -13,8 +13,7 @@ LOGGER = logging.getLogger("matrix_webhook.handler")
|
||||
|
||||
|
||||
async def matrix_webhook(request):
|
||||
"""
|
||||
Coroutine given to the server, st. it knows what to do with an HTTP request.
|
||||
"""Coroutine given to the server, st. it knows what to do with an HTTP request.
|
||||
|
||||
This one handles a POST, checks its content, and forwards it to the matrix room.
|
||||
"""
|
||||
@@ -37,11 +36,13 @@ async def matrix_webhook(request):
|
||||
if "formatter" in request.rel_url.query:
|
||||
try:
|
||||
data = getattr(formatters, request.rel_url.query["formatter"])(
|
||||
data, request.headers
|
||||
data,
|
||||
request.headers,
|
||||
)
|
||||
except AttributeError:
|
||||
return utils.create_json_response(
|
||||
HTTPStatus.BAD_REQUEST, "Unknown formatter"
|
||||
HTTPStatus.BAD_REQUEST,
|
||||
"Unknown formatter",
|
||||
)
|
||||
|
||||
if "room_id" in request.rel_url.query and "room_id" not in data:
|
||||
@@ -56,7 +57,8 @@ async def matrix_webhook(request):
|
||||
data["key"] = conf.API_KEY
|
||||
else: # but if there is a wrong digest, an informative error should be provided
|
||||
return utils.create_json_response(
|
||||
HTTPStatus.UNAUTHORIZED, "Invalid SHA-256 HMAC digest"
|
||||
HTTPStatus.UNAUTHORIZED,
|
||||
"Invalid SHA-256 HMAC digest",
|
||||
)
|
||||
|
||||
missing = []
|
||||
@@ -65,7 +67,8 @@ async def matrix_webhook(request):
|
||||
missing.append(key)
|
||||
if missing:
|
||||
return utils.create_json_response(
|
||||
HTTPStatus.BAD_REQUEST, f"Missing {', '.join(missing)}"
|
||||
HTTPStatus.BAD_REQUEST,
|
||||
f"Missing {', '.join(missing)}",
|
||||
)
|
||||
|
||||
if data["key"] != conf.API_KEY:
|
||||
|
||||
@@ -63,7 +63,9 @@ async def send_room_message(room_id, content):
|
||||
for _ in range(10):
|
||||
try:
|
||||
resp = await CLIENT.room_send(
|
||||
room_id=room_id, message_type="m.room.message", content=content
|
||||
room_id=room_id,
|
||||
message_type="m.room.message",
|
||||
content=content,
|
||||
)
|
||||
if isinstance(resp, RoomSendError):
|
||||
if resp.status_code == "M_UNKNOWN_TOKEN":
|
||||
|
||||
Reference in New Issue
Block a user