2022-04-02 21:07:11 +02:00
|
|
|
"""
|
|
|
|
Project is under GNU GENERAL PUBLIC LICENSE 3.0
|
|
|
|
|
|
|
|
2022, created by Specoolazius
|
|
|
|
"""
|
2022-04-03 08:42:45 +02:00
|
|
|
import os.path
|
2022-04-02 21:07:11 +02:00
|
|
|
|
2022-04-02 21:03:31 +02:00
|
|
|
import discord
|
|
|
|
from discord.commands import slash_command
|
|
|
|
|
|
|
|
from libs import Client
|
|
|
|
|
|
|
|
|
|
|
|
class StartStop(discord.Cog):
|
|
|
|
"""< discord.Cog >
|
|
|
|
|
|
|
|
Extension for starting and stopping the Minecraft server.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, bot: Client):
|
|
|
|
self.bot = bot
|
|
|
|
|
|
|
|
@slash_command(name='start')
|
|
|
|
async def __execute_start(self, ctx: discord.ApplicationContext) -> None:
|
2022-04-03 08:42:45 +02:00
|
|
|
await ctx.defer()
|
|
|
|
self.bot.is_server_starting = True
|
|
|
|
|
|
|
|
try:
|
|
|
|
returncode = await self.bot.execute_shell('start.sh')
|
|
|
|
self.bot.logger.info(f'Executed start.sh with exit code {returncode}')
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
self.bot.logger.error(
|
|
|
|
f'Failed to run start.sh\n'
|
|
|
|
f'Error: {e}'
|
|
|
|
)
|
|
|
|
await ctx.respond(
|
|
|
|
f'Failed to execute start.sh\n'
|
|
|
|
f'Check {os.path.join(self.bot.config.log_path, "discord.log")} for more detailed information'
|
|
|
|
)
|
|
|
|
|
|
|
|
else:
|
|
|
|
await ctx.respond('Server is starting')
|
2022-04-02 21:41:14 +02:00
|
|
|
|
|
|
|
@slash_command(name='stop')
|
|
|
|
async def __execute_stop(self, ctx: discord.ApplicationContext) -> None:
|
2022-04-03 08:42:45 +02:00
|
|
|
await ctx.defer()
|
|
|
|
await ctx.respond('Not implemented yet')
|