mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-27 13:34:28 +00:00
Add ping command
This commit is contained in:
parent
4e6c2d9ed3
commit
d009f63a07
4 changed files with 69 additions and 0 deletions
|
@ -61,6 +61,7 @@ from .magicktreasure import MagicktreasureCommand
|
||||||
from .treasure import TreasureCommand
|
from .treasure import TreasureCommand
|
||||||
from .givetreasure import GivetreasureCommand
|
from .givetreasure import GivetreasureCommand
|
||||||
from .cat import CatCommand
|
from .cat import CatCommand
|
||||||
|
from .ping import PingCommand
|
||||||
|
|
||||||
# Enter the commands of your Pack here!
|
# Enter the commands of your Pack here!
|
||||||
available_commands = [
|
available_commands = [
|
||||||
|
@ -126,6 +127,7 @@ available_commands = [
|
||||||
TreasureCommand,
|
TreasureCommand,
|
||||||
GivetreasureCommand,
|
GivetreasureCommand,
|
||||||
CatCommand,
|
CatCommand,
|
||||||
|
PingCommand,
|
||||||
]
|
]
|
||||||
|
|
||||||
# Don't change this, it should automatically generate __all__
|
# Don't change this, it should automatically generate __all__
|
||||||
|
|
55
royalpack/commands/ping.py
Normal file
55
royalpack/commands/ping.py
Normal 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))
|
|
@ -8,6 +8,7 @@ from .discord_pause import DiscordPauseEvent
|
||||||
from .discord_playable import DiscordPlaymodeEvent
|
from .discord_playable import DiscordPlaymodeEvent
|
||||||
from .discord_lazy_play import DiscordLazyPlayEvent
|
from .discord_lazy_play import DiscordLazyPlayEvent
|
||||||
from .telegram_message import TelegramMessageEvent
|
from .telegram_message import TelegramMessageEvent
|
||||||
|
from .pong import PongEvent
|
||||||
|
|
||||||
# Enter the commands of your Pack here!
|
# Enter the commands of your Pack here!
|
||||||
available_events = [
|
available_events = [
|
||||||
|
@ -20,6 +21,7 @@ available_events = [
|
||||||
DiscordPlaymodeEvent,
|
DiscordPlaymodeEvent,
|
||||||
DiscordLazyPlayEvent,
|
DiscordLazyPlayEvent,
|
||||||
TelegramMessageEvent,
|
TelegramMessageEvent,
|
||||||
|
PongEvent,
|
||||||
]
|
]
|
||||||
|
|
||||||
# Don't change this, it should automatically generate __all__
|
# Don't change this, it should automatically generate __all__
|
||||||
|
|
10
royalpack/events/pong.py
Normal file
10
royalpack/events/pong.py
Normal 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"}
|
Loading…
Reference in a new issue