chore(pterodactyl): clean up some dirty code
This commit is contained in:
parent
b4a54d214d
commit
1c0f12660b
1 changed files with 27 additions and 55 deletions
|
@ -9,7 +9,7 @@ from pydactyl import PterodactylClient
|
|||
from redbot.core import app_commands, commands
|
||||
from redbot.core.app_commands import Choice
|
||||
from redbot.core.bot import Red
|
||||
from redbot.core.utils.chat_formatting import box, error, humanize_list
|
||||
from redbot.core.utils.chat_formatting import bold, box, error, humanize_list
|
||||
from redbot.core.utils.views import ConfirmView
|
||||
|
||||
from pterodactyl import mcsrvstatus
|
||||
|
@ -20,8 +20,9 @@ from pterodactyl.logger import logger
|
|||
class Pterodactyl(commands.Cog):
|
||||
"""Pterodactyl allows you to manage your Pterodactyl Panel from Discord."""
|
||||
|
||||
__author__ = ["SeaswimmerTheFsh"]
|
||||
__version__ = "2.0.0"
|
||||
__author__ = ["[cswimr](https://www.coastalcommits.com/cswimr)"]
|
||||
__git__ = "https://www.coastalcommits.com/cswimr/SeaCogs"
|
||||
__version__ = "2.0.1"
|
||||
__documentation__ = "https://seacogs.coastalcommits.com/pterodactyl/"
|
||||
|
||||
def __init__(self, bot: Red):
|
||||
|
@ -39,9 +40,9 @@ class Pterodactyl(commands.Cog):
|
|||
n = "\n" if "\n\n" not in pre_processed else ""
|
||||
text = [
|
||||
f"{pre_processed}{n}",
|
||||
f"Cog Version: **{self.__version__}**",
|
||||
f"Author: {humanize_list(self.__author__)}",
|
||||
f"Documentation: {self.__documentation__}",
|
||||
f"{bold('Cog Version:')} [{self.__version__}]({self.__git__})",
|
||||
f"{bold('Author:')} {humanize_list(self.__author__)}",
|
||||
f"{bold('Documentation:')} {self.__documentation__}",
|
||||
]
|
||||
return "\n".join(text)
|
||||
|
||||
|
@ -175,65 +176,36 @@ class Pterodactyl(commands.Cog):
|
|||
|
||||
async def power(self, ctx: Union[discord.Interaction, commands.Context], action: str, action_ing: str, warning: str = '') -> None:
|
||||
if isinstance(ctx, discord.Interaction):
|
||||
author = ctx.user
|
||||
else:
|
||||
author = ctx.author
|
||||
ctx = await self.bot.get_context(ctx)
|
||||
|
||||
current_status = await config.current_status()
|
||||
|
||||
if current_status == action_ing:
|
||||
if isinstance(ctx, discord.Interaction):
|
||||
return await ctx.response.send_message(f"Server is already {action_ing}.", ephemeral=True)
|
||||
return await ctx.send(f"Server is already {action_ing}.")
|
||||
return await ctx.send(f"Server is already {action_ing}.", ephemeral=True)
|
||||
|
||||
if current_status in ["starting", "stopping"] and action != "kill":
|
||||
if isinstance(ctx, discord.Interaction):
|
||||
return await ctx.response.send_message("Another power action is already in progress.", ephemeral=True)
|
||||
return await ctx.send("Another power action is already in progress.")
|
||||
return await ctx.send("Another power action is already in progress.", ephemeral=True)
|
||||
|
||||
view = ConfirmView(author, disable_buttons=True)
|
||||
view = ConfirmView(ctx.author, disable_buttons=True)
|
||||
|
||||
if isinstance(ctx, discord.Interaction):
|
||||
await ctx.response.send_message(f"{warning}Are you sure you want to {action} the server?", view=view)
|
||||
else:
|
||||
message = await ctx.send(f"{warning}Are you sure you want to {action} the server?", view=view)
|
||||
|
||||
await view.wait()
|
||||
|
||||
if view.result is True:
|
||||
if isinstance(ctx, discord.Interaction):
|
||||
await ctx.edit_original_response(content=f"Sending websocket command to {action} server...", view=None)
|
||||
else:
|
||||
await message.edit(content=f"Sending websocket command to {action} server...", view=None)
|
||||
|
||||
await self.websocket.send(json.dumps({"event": "set state", "args": [action]}))
|
||||
|
||||
if isinstance(ctx, discord.Interaction):
|
||||
await ctx.edit_original_response(content=f"Server {action_ing}", view=None)
|
||||
else:
|
||||
await message.edit(content=f"Server {action_ing}", view=None)
|
||||
|
||||
else:
|
||||
if isinstance(ctx, discord.Interaction):
|
||||
await ctx.edit_original_response(content="Cancelled.", view=None)
|
||||
else:
|
||||
await message.edit(content="Cancelled.", view=None)
|
||||
|
||||
async def send_command(self, ctx: Union[discord.Interaction, commands.Context], command: str):
|
||||
channel = self.bot.get_channel(await config.console_channel())
|
||||
if isinstance(ctx, discord.Interaction):
|
||||
if channel:
|
||||
await channel.send(f"Received console command from {ctx.user.id}: {command[:1900]}", allowed_mentions=discord.AllowedMentions.none())
|
||||
try:
|
||||
await self.websocket.send(json.dumps({"event": "send command", "args": [command]}))
|
||||
await ctx.response.send_message(f"Command sent to server. {box(command, 'json')}", ephemeral=True)
|
||||
except websockets.exceptions.ConnectionClosed as e:
|
||||
logger.error("WebSocket connection closed: %s", e)
|
||||
await ctx.response.send_message(error("WebSocket connection closed."))
|
||||
self.task.cancel()
|
||||
self.retry_counter = 0
|
||||
self.task = self.get_task()
|
||||
else:
|
||||
ctx = await self.bot.get_context(ctx)
|
||||
if channel:
|
||||
await channel.send(f"Received console command from {ctx.author.id}: {command[:1900]}", allowed_mentions=discord.AllowedMentions.none())
|
||||
try:
|
||||
|
|
Loading…
Reference in a new issue