MCPcopy Create free account
hub / github.com/ScaleML/AgentSPEX / update_vm_env

Function update_vm_env

scripts/setup_discord.py:94–112  ·  view source on GitHub ↗

Update config/vm.env with Discord bot token and optional slash command.

(token: str, slash_command: str = "")

Source from the content-addressed store, hash-verified

92
93
94def update_vm_env(token: str, slash_command: str = "") -> bool:
95 """Update config/vm.env with Discord bot token and optional slash command."""
96 try:
97 content = VM_ENV_PATH.read_text() if VM_ENV_PATH.exists() else ""
98
99 def upsert(key: str, value: str, text: str) -> str:
100 if f"{key}=" in text:
101 return re.sub(rf"{key}=.*", f"{key}={value}", text)
102 return text + f"\n{key}={value}"
103
104 content = upsert("DISCORD_BOT_TOKEN", token, content)
105 if slash_command:
106 content = upsert("DISCORD_SLASH_COMMAND", slash_command, content)
107
108 VM_ENV_PATH.write_text(content)
109 return True
110 except Exception as e:
111 print_error(f"Failed to update {VM_ENV_PATH}: {e}")
112 return False
113
114
115def main():

Callers 1

mainFunction · 0.70

Calls 2

upsertFunction · 0.85
print_errorFunction · 0.70

Tested by

no test coverage detected