1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-24 03:54:20 +00:00
royalnet/royalpack/commands/ping.py

37 lines
983 B
Python
Raw Normal View History

2020-06-30 22:11:14 +00:00
import asyncio
from typing import *
import royalnet
import royalnet.commands as rc
class PingCommand(rc.Command):
name: str = "ping"
description: str = "Display the status of the Herald network."
syntax: str = ""
2020-06-30 23:08:09 +00:00
_targets = ["telegram", "discord", "matrix", "constellation"]
2020-06-30 22:11:14 +00:00
async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None:
await data.reply("📶 Ping...")
2020-06-30 23:08:09 +00:00
tasks = {}
2020-06-30 22:11:14 +00:00
2020-06-30 23:08:09 +00:00
for target in self._targets:
tasks[target] = self.loop.create_task(self.interface.call_herald_event(target, "pong"))
2020-06-30 22:11:14 +00:00
await asyncio.sleep(10)
lines = ["📶 [b]Pong![/b]", ""]
2020-06-30 23:08:09 +00:00
for name, task in tasks.items():
try:
print(task.result())
except (asyncio.CancelledError, asyncio.InvalidStateError):
lines.append(f"🔴 [c]{name}[/c]")
else:
lines.append(f"🔵 [c]{name}[/c]")
2020-06-30 22:11:14 +00:00
await data.reply("\n".join(lines))