deduplicate command handler logic

This commit is contained in:
Kay Faraday 2023-09-11 18:22:24 +00:00
parent 40fad78407
commit f593af4fa2
1 changed files with 8 additions and 4 deletions

View File

@ -21,14 +21,18 @@ async def main():
anyio.create_task_group() as nursery,
):
async for notif in pleroma.stream_notifications():
handler = None
if 'opt out' in notif['status']['content']:
nursery.start_soon(opt_out, db, pleroma, notif['status'])
handler = opt_out
elif 'opt in' in notif['status']['content']:
nursery.start_soon(opt_in, db, pleroma, notif['status'])
handler = opt_in
elif 'status' in notif['status']['content']:
nursery.start_soon(status, db, pleroma, notif['status'])
handler = status
elif 'help' in notif['status']['content']:
nursery.start_soon(help, db, pleroma, notif['status'])
handler = help
if handler:
nursery.start_soon(handler, db, pleroma, notif['status'])
async def opt_out(db, pleroma, status):
await db.execute(