From 23594fc4ac9abf59a5269b24422a8b25711bba27 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Mon, 8 Apr 2019 10:47:57 +0200 Subject: [PATCH] Create delayed ping --- royalnet/commands/ping.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/royalnet/commands/ping.py b/royalnet/commands/ping.py index 9ecb5a41..87d689e5 100644 --- a/royalnet/commands/ping.py +++ b/royalnet/commands/ping.py @@ -1,11 +1,19 @@ -from ..utils import Command, CommandArgs, Call +import asyncio +from ..utils import Command, CommandArgs, Call, InvalidInputError class PingCommand(Command): command_name = "ping" command_description = "Ping pong!" - command_syntax = "" + command_syntax = "[time_to_wait]" async def common(self, call: Call): + try: + time = int(call.args[0]) + except InvalidInputError: + time = 0 + except ValueError: + raise InvalidInputError("time_to_wait is not a number") + await asyncio.sleep(time) await call.reply("🏓 Pong!")