diff --git a/royalpack/commands/__init__.py b/royalpack/commands/__init__.py index fecb9e04..b7e3ee3d 100644 --- a/royalpack/commands/__init__.py +++ b/royalpack/commands/__init__.py @@ -61,6 +61,7 @@ from .magicktreasure import MagicktreasureCommand from .treasure import TreasureCommand from .givetreasure import GivetreasureCommand from .cat import CatCommand +from .ping import PingCommand # Enter the commands of your Pack here! available_commands = [ @@ -126,6 +127,7 @@ available_commands = [ TreasureCommand, GivetreasureCommand, CatCommand, + PingCommand, ] # Don't change this, it should automatically generate __all__ diff --git a/royalpack/commands/ping.py b/royalpack/commands/ping.py new file mode 100644 index 00000000..d8f17b79 --- /dev/null +++ b/royalpack/commands/ping.py @@ -0,0 +1,55 @@ +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 = "" + + async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None: + await data.reply("📶 Ping...") + + telegram_c = self.interface.call_herald_event("telegram", "pong") + discord_c = self.interface.call_herald_event("discord", "pong") + constellation_c = self.interface.call_herald_event("constellation", "pong") + + telegram_t = self.loop.create_task(telegram_c) + discord_t = self.loop.create_task(discord_c) + constellation_t = self.loop.create_task(constellation_c) + + await asyncio.sleep(10) + + try: + telegram_r = telegram_t.result() + except (asyncio.CancelledError, asyncio.InvalidStateError): + telegram_r = None + try: + discord_r = discord_t.result() + except (asyncio.CancelledError, asyncio.InvalidStateError): + discord_r = None + try: + constellation_r = constellation_t.result() + except (asyncio.CancelledError, asyncio.InvalidStateError): + constellation_r = None + + lines = ["📶 [b]Pong![/b]", ""] + + if telegram_r: + lines.append("🔵 Telegram") + else: + lines.append("🔴 Telegram") + if discord_r: + lines.append("🔵 Discord") + else: + lines.append("🔴 Discord") + if constellation_r: + lines.append("🔵 Constellation") + else: + lines.append("🔴 Constellation") + + await data.reply("\n".join(lines)) diff --git a/royalpack/events/__init__.py b/royalpack/events/__init__.py index 380d5cb2..03ae8b08 100644 --- a/royalpack/events/__init__.py +++ b/royalpack/events/__init__.py @@ -8,6 +8,7 @@ from .discord_pause import DiscordPauseEvent from .discord_playable import DiscordPlaymodeEvent from .discord_lazy_play import DiscordLazyPlayEvent from .telegram_message import TelegramMessageEvent +from .pong import PongEvent # Enter the commands of your Pack here! available_events = [ @@ -20,6 +21,7 @@ available_events = [ DiscordPlaymodeEvent, DiscordLazyPlayEvent, TelegramMessageEvent, + PongEvent, ] # Don't change this, it should automatically generate __all__ diff --git a/royalpack/events/pong.py b/royalpack/events/pong.py new file mode 100644 index 00000000..d62e6026 --- /dev/null +++ b/royalpack/events/pong.py @@ -0,0 +1,10 @@ +from typing import * +import royalnet +import royalnet.commands as rc + + +class PongEvent(rc.Event): + name = "pong" + + async def run(self, **kwargs) -> dict: + return {"status": "connected"}