Setup Dynamic Environment #3697
Closed
TonyDeRosia
started this conversation in
Community Contribs & Snippets
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I shared the basic script for my dynamic auto loader but if that was giving issues then here is an option, this will do most of the work for you to set up your dynamic auto load environment.
import os
Define paths
BASE_DIR = os.path.abspath(os.path.join(os.path.dirname(file), ".."))
COMMANDS_DIR = os.path.join(BASE_DIR, "commands")
DYNAMIC_DIR = os.path.join(COMMANDS_DIR, "dynamic")
DEFAULT_CMDSETS_FILE = os.path.join(COMMANDS_DIR, "default_cmdsets.py")
AUTO_LOADER_FILE = os.path.join(COMMANDS_DIR, "command_auto_loader.py")
HELLO_COMMAND_FILE = os.path.join(DYNAMIC_DIR, "hello.py")
Auto-loader script content
AUTO_LOADER_CONTENT = """
import os
import importlib.util
from evennia.utils import logger
from evennia import Command
def setup_dynamic_commands(cmdset):
"""
Automatically load commands from the dynamic folder.
"""
dynamic_dir = os.path.join(os.path.dirname(file), "dynamic")
if not os.path.exists(dynamic_dir):
logger.log_err("[ERROR] Dynamic directory does not exist.")
return
"""
Basic hello command content
HELLO_COMMAND_CONTENT = """
from evennia import Command
class CmdHello(Command):
key = "hello"
help_category = "General"
"""
Function to ensure directories and files exist
def ensure_directories_and_files():
# Create the dynamic folder if it doesn't exist
if not os.path.exists(DYNAMIC_DIR):
os.makedirs(DYNAMIC_DIR)
print(f"[INFO] Created dynamic directory: {DYNAMIC_DIR}")
Function to modify default_cmdsets.py
def modify_default_cmdsets():
if not os.path.exists(DEFAULT_CMDSETS_FILE):
print(f"[ERROR] {DEFAULT_CMDSETS_FILE} does not exist. Ensure you're in the correct project.")
return
Main setup function
def main():
ensure_directories_and_files()
modify_default_cmdsets()
print("[SUCCESS] Command auto-loader setup is complete. Restart Evennia to test the 'hello' command.")
if name == "main":
main()
Beta Was this translation helpful? Give feedback.
All reactions