diff --git a/bot/botclient.py b/bot/botclient.py index c3ef41f..c472486 100644 --- a/bot/botclient.py +++ b/bot/botclient.py @@ -300,7 +300,55 @@ class Status(discord.Cog): def __init__(self, bot: BotClient): self.bot = bot + self.mc_server = self.bot.mc_server + @slash_command(name='info') + async def __show_server_info(self, ctx: discord.ApplicationContext) -> None: + print() + """ + .add_field( + name='Version', + value="\n".join(re.split(", | ", status.version.name)), + ) + """ + + @slash_command(name='status') + async def __show_status(self, ctx: discord.ApplicationContext) -> None: + print('exec') + await ctx.defer() + try: + status: mcstatus.pinger.PingResponse = await self.mc_server.async_status() + pprint.pprint(vars(status)) + + query = await self.mc_server.async_query() + pprint.pprint(vars(query)) + + await ctx.respond( + embed=discord.Embed( + title=f'Minecraft server status!', + description=f'(**{self.bot.config.server_address}** on port {self.bot.config.server_port})', + colour=self.bot.color, + timestamp=datetime.now() + ).add_field( + name='Server Ping', + value=f'**īš‚**``{round(status.latency, 2)} ms``', + # value=f'**⌊** **🏓 Pong!** with **``{round(status.latency, 2)}``** ms' + ).add_field( + name='Players online', + value=f'**īš‚** ``{status.players.online} players``', + ) + ) + + except asyncio.TimeoutError or OSError: + # ToDo: Check os Error on booting + # ToDo: add is starting and create embed + await ctx.respond(embed=discord.Embed( + title=f'Server offline', + description=f'(**{self.bot.config.server_address}** on port {self.bot.config.server_port})', + colour=self.bot.color, + timestamp=datetime.now() + ) + ) class StartStop(discord.Cog):