mirror of
https://github.com/opus-tango/minecraft-server-discord-bot.git
synced 2026-03-20 03:55:20 +00:00
fix forcestop and prevent botstop if server running
This commit is contained in:
17
bot.py
17
bot.py
@@ -211,7 +211,7 @@ async def _stop_server_internal(ctx, servername, method):
|
|||||||
if method == "stop":
|
if method == "stop":
|
||||||
command_to_send = 'stop\n'
|
command_to_send = 'stop\n'
|
||||||
elif method == "forcestop":
|
elif method == "forcestop":
|
||||||
command_to_send = "$'\\003'" # Ctrl+C
|
command_to_send = "$'\003'" # Ctrl+C
|
||||||
else:
|
else:
|
||||||
await ctx.send("Invalid stop method.")
|
await ctx.send("Invalid stop method.")
|
||||||
return
|
return
|
||||||
@@ -496,18 +496,11 @@ async def botstop(ctx):
|
|||||||
'''
|
'''
|
||||||
global active_server, active_server_pipe_task
|
global active_server, active_server_pipe_task
|
||||||
|
|
||||||
if active_server_pipe_task:
|
if active_server is not None:
|
||||||
active_server_pipe_task.cancel()
|
await ctx.send(f"Server running, please stop the server before stopping the bot.")
|
||||||
try:
|
return
|
||||||
await active_server_pipe_task # Await to ensure it cleans up
|
|
||||||
except asyncio.CancelledError:
|
|
||||||
pass # Expected
|
|
||||||
active_server_pipe_task = None
|
|
||||||
|
|
||||||
if active_server:
|
|
||||||
await _delete_named_pipe(active_server) # Delete the pipe file
|
|
||||||
|
|
||||||
|
|
||||||
await bot.close()
|
await bot.close()
|
||||||
|
print("Bot stopped.")
|
||||||
|
|
||||||
bot.run(TOKEN)
|
bot.run(TOKEN)
|
||||||
|
|||||||
Reference in New Issue
Block a user