Handler engine now has support for missing argument defaults

This commit is contained in:
Ben 2019-12-02 23:31:53 +00:00
parent 91a4d8acd5
commit db3825ccca
2 changed files with 15 additions and 10 deletions

View File

@ -88,7 +88,14 @@ class _ArgumentDeserializer:
if ctx.component.annotation is ctx.component.empty and ctx.component.default is not ctx.component.empty:
handler_call_arguments.append(ctx.component.default)
elif ctx.component.kind == ctx.component.POSITIONAL_OR_KEYWORD:
ctx.argument = next(ctx.arguments)
ctx.argument = next(ctx.arguments, None)
if ctx.argument is None:
if ctx.component.default is not ctx.component.empty:
handler_call_arguments.append(ctx.component.default)
else:
raise StopIteration
else:
converter = get_converter(ctx.component)
if converter == str:

View File

@ -58,12 +58,10 @@ async def handle_moderator_ban(p, penguin_id: int, ban_type: int, reason: int, d
@handlers.handler(XTPacket('m', 'r'))
async def handle_report(p, penguin_id: int, *reason):
reason = int(reason[0]) if reason else 0
async def handle_report(p, penguin_id: int, reason: int = 0):
date_now = datetime.datetime.now()
server_id = p.server.server_config['Id']
await Report.create(penguin_id=penguin_id, reporter_id=p.data.id, report_type=reason,
date=date_now, server_id=server_id, room_id=p.room.id)
await Report.create(penguin_id=penguin_id, reporter_id=p.id, report_type=reason,
date=date_now, server_id=p.server.config.id, room_id=p.room.id)
@handlers.handler(XTPacket('o', 'moderatormessage'))