1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00

Add ping command

This commit is contained in:
Steffo 2020-07-01 00:11:14 +02:00
parent 4e6c2d9ed3
commit d009f63a07
Signed by: steffo
GPG key ID: 896A80F55F7C97F0
4 changed files with 69 additions and 0 deletions

View file

@ -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__

View file

@ -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))

View file

@ -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__

10
royalpack/events/pong.py Normal file
View file

@ -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"}