forked from blizzthewolf/SeaCogs
feat(pterodactyl): added console channel support
This commit is contained in:
parent
d9f5d14f40
commit
cebc2223d9
1 changed files with 13 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
import discord
|
||||||
import websockets
|
import websockets
|
||||||
from pydactyl import PterodactylClient, exceptions
|
from pydactyl import PterodactylClient, exceptions
|
||||||
from redbot.core import Config, commands
|
from redbot.core import Config, commands
|
||||||
|
@ -17,6 +18,7 @@ class Pterodactyl(commands.Cog):
|
||||||
base_url=None,
|
base_url=None,
|
||||||
api_key=None,
|
api_key=None,
|
||||||
server_id=None,
|
server_id=None,
|
||||||
|
console_channel=None,
|
||||||
startup_jar=None,
|
startup_jar=None,
|
||||||
startup_arguments=None,
|
startup_arguments=None,
|
||||||
power_action_in_progress=False
|
power_action_in_progress=False
|
||||||
|
@ -66,9 +68,14 @@ class Pterodactyl(commands.Cog):
|
||||||
auth_message = json.dumps({"event": "auth", "args": [websocket_credentials['data']['token']]})
|
auth_message = json.dumps({"event": "auth", "args": [websocket_credentials['data']['token']]})
|
||||||
await websocket.send(auth_message)
|
await websocket.send(auth_message)
|
||||||
self.logger.debug("Authentication message sent")
|
self.logger.debug("Authentication message sent")
|
||||||
|
|
||||||
if json.loads(message)['event'] == 'auth success':
|
if json.loads(message)['event'] == 'auth success':
|
||||||
self.logger.debug("Authentication successful")
|
self.logger.debug("Authentication successful")
|
||||||
self.logger.debug("Received message: %s", message)
|
|
||||||
|
if json.loads(message)['event'] == 'console output' and await self.config.console_channel() is not None:
|
||||||
|
channel = self.bot.get_channel(await self.config.console_channel)
|
||||||
|
await channel.send(json.loads(message)['args'][0])
|
||||||
|
#FIXME - Add pagification for long messages to prevent Discord API errors
|
||||||
except websockets.exceptions.ConnectionClosed as e:
|
except websockets.exceptions.ConnectionClosed as e:
|
||||||
self.logger.debug("WebSocket connection closed: %s", e)
|
self.logger.debug("WebSocket connection closed: %s", e)
|
||||||
websocket_credentials = client.servers.get_websocket(server_id)
|
websocket_credentials = client.servers.get_websocket(server_id)
|
||||||
|
@ -84,6 +91,11 @@ class Pterodactyl(commands.Cog):
|
||||||
self.task.cancel()
|
self.task.cancel()
|
||||||
await self.client._session.close() # pylint: disable=protected-access
|
await self.client._session.close() # pylint: disable=protected-access
|
||||||
|
|
||||||
|
@commands.cog.listener()
|
||||||
|
async def on_message(self, message: discord.Message):
|
||||||
|
if message.channel.id == await self.config.console_channel():
|
||||||
|
self.websocket.send(json.dumps({"event": "send command", "args": [message.content]}))
|
||||||
|
|
||||||
@commands.group(autohelp = True, name = "pterodactyl", aliases = ["ptero"])
|
@commands.group(autohelp = True, name = "pterodactyl", aliases = ["ptero"])
|
||||||
async def pterodactyl(self, ctx: commands.Context):
|
async def pterodactyl(self, ctx: commands.Context):
|
||||||
"""Pterodactyl allows you to manage your Pterodactyl Panel from Discord."""
|
"""Pterodactyl allows you to manage your Pterodactyl Panel from Discord."""
|
||||||
|
|
Loading…
Reference in a new issue