Adding custom commands #13
-
could you share how one would make the chat bot interact with custom commands |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
i want to add functionss like turning off pc and etc.... |
Beta Was this translation helpful? Give feedback.
-
To add custom commands, you'd use the Plugins feature I made. Here's the link to the documentation How to Write Plugins for MILES. To start you off, you need to understand the docstring format required, which is outlined, and you just need a python function that takes in an arg, which can be anything, confirmation yes or no, or a number, or a string, literally anything. That python function should complete the task you want when provided with the correct arg. Here's a function I've drafted for you: import subprocess
import platform
def shutdown_computer(argument):
"""
Description: Shuts down the computer with a 5-second delay if the correct argument 'shutdown_now' is provided. Returns True if the command was successful, otherwise False.
Parameter Description for {argument}: A string to check against a predefined value to initiate shutdown. The only valid argument to initiate shutdown is 'shutdown_now'.
Required Parameters: {argument}
Main Function: Yes
"""
expected_argument = "shutdown_now"
success = False
if argument == expected_argument:
print("[Miles is scheduling your computer to shutdown in 5 seconds…]")
# Detect operating system
os_type = platform.system().lower()
try:
# Command to shutdown computer depending on the OS
if os_type == "windows":
subprocess.run(["shutdown", "/s", "/t", "5"], check=True)
elif os_type == "darwin": # macOS's system name in Python's platform module
subprocess.run(["sudo", "shutdown", "-h", "+0.083"], check=True) # macOS command adjusted
success = True
except subprocess.CalledProcessError:
print("Failed to execute shutdown command.")
success = False
else:
print("Invalid argument. No action taken.")
success = False
return success Place this entire function inside the plugins file anywhere you want then save it. Once you run Miles again, it will automatically add the plugin and generate the rest of the components to make it work. If you have any other questions, I'd be glad to help. |
Beta Was this translation helpful? Give feedback.
To add custom commands, you'd use the Plugins feature I made. Here's the link to the documentation How to Write Plugins for MILES.
To start you off, you need to understand the docstring format required, which is outlined, and you just need a python function that takes in an arg, which can be anything, confirmation yes or no, or a number, or a string, literally anything. That python function should complete the task you want when provided with the correct arg. Here's a function I've drafted for you: