This commit is contained in:
Slipstream 2025-04-30 10:36:46 -06:00
parent 34047a9581
commit 262cebe7c6
Signed by: slipstream
GPG Key ID: 13E498CE010AC6FD
2 changed files with 14 additions and 2 deletions

View File

@ -950,7 +950,12 @@ def create_tools_list():
description="Restarts the Gurt bot process by re-executing the current Python script. Use with caution.",
parameters={
"type": "object",
"properties": {},
"properties": {
"channel_id": {
"type": "string",
"description": "The ID of the channel to send the restart message in. If not provided, no message is sent."
}
},
"required": []
}
)

View File

@ -1069,13 +1069,20 @@ async def send_discord_message(cog: commands.Cog, channel_id: str, message_conte
"""Sends a message to a specified Discord channel."""
print(f"Attempting to send message to channel {channel_id}: {message_content[:100]}...")
async def restart_gurt_bot(cog: commands.Cog) -> Dict[str, Any]:
async def restart_gurt_bot(cog: commands.Cog, channel_id: str = None) -> Dict[str, Any]:
"""
Restarts the Gurt bot process by re-executing the current Python script.
Sends a message in the channel before restarting.
Returns a status dictionary. Only works if the bot process has permission.
"""
import sys
import os
# Send message before restarting
if channel_id:
try:
await send_discord_message(cog, channel_id, "Restart tool was called.")
except Exception as msg_exc:
print(f"Failed to send restart message: {msg_exc}")
try:
python = sys.executable
os.execv(python, [python] + sys.argv)