Update config/vm.env with Discord bot token and optional slash command.
(token: str, slash_command: str = "")
| 92 | |
| 93 | |
| 94 | def 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 | |
| 115 | def main(): |
no test coverage detected