1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-27 13:34:28 +00:00

Create delayed ping

This commit is contained in:
Steffo 2019-04-08 10:47:57 +02:00
parent a01402d383
commit 23594fc4ac

View file

@ -1,11 +1,19 @@
from ..utils import Command, CommandArgs, Call import asyncio
from ..utils import Command, CommandArgs, Call, InvalidInputError
class PingCommand(Command): class PingCommand(Command):
command_name = "ping" command_name = "ping"
command_description = "Ping pong!" command_description = "Ping pong!"
command_syntax = "" command_syntax = "[time_to_wait]"
async def common(self, call: Call): 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!") await call.reply("🏓 Pong!")