Update config/vm.env with Slack tokens, bot name, and slash command.
(
bot_token: str, app_token: str, bot_name: str = "", slash_command: str = ""
)
| 122 | |
| 123 | |
| 124 | def update_vm_env( |
| 125 | bot_token: str, app_token: str, bot_name: str = "", slash_command: str = "" |
| 126 | ) -> bool: |
| 127 | """Update config/vm.env with Slack tokens, bot name, and slash command.""" |
| 128 | try: |
| 129 | # Read existing content |
| 130 | if VM_ENV_PATH.exists(): |
| 131 | with open(VM_ENV_PATH, "r") as f: |
| 132 | content = f.read() |
| 133 | else: |
| 134 | content = "" |
| 135 | |
| 136 | # Update or add SLACK_BOT_TOKEN |
| 137 | if "SLACK_BOT_TOKEN=" in content: |
| 138 | content = re.sub( |
| 139 | r"SLACK_BOT_TOKEN=.*", |
| 140 | f"SLACK_BOT_TOKEN={bot_token}", |
| 141 | content, |
| 142 | ) |
| 143 | else: |
| 144 | content += f"\nSLACK_BOT_TOKEN={bot_token}" |
| 145 | |
| 146 | # Update or add SLACK_APP_TOKEN |
| 147 | if "SLACK_APP_TOKEN=" in content: |
| 148 | content = re.sub( |
| 149 | r"SLACK_APP_TOKEN=.*", |
| 150 | f"SLACK_APP_TOKEN={app_token}", |
| 151 | content, |
| 152 | ) |
| 153 | else: |
| 154 | content += f"\nSLACK_APP_TOKEN={app_token}" |
| 155 | |
| 156 | # Update or add SLACK_BOT_NAME |
| 157 | if bot_name: |
| 158 | if "SLACK_BOT_NAME=" in content: |
| 159 | content = re.sub( |
| 160 | r"SLACK_BOT_NAME=.*", |
| 161 | f"SLACK_BOT_NAME={bot_name}", |
| 162 | content, |
| 163 | ) |
| 164 | else: |
| 165 | content += f"\nSLACK_BOT_NAME={bot_name}" |
| 166 | |
| 167 | # Update or add SLACK_SLASH_COMMAND |
| 168 | if slash_command: |
| 169 | if "SLACK_SLASH_COMMAND=" in content: |
| 170 | content = re.sub( |
| 171 | r"SLACK_SLASH_COMMAND=.*", |
| 172 | f"SLACK_SLASH_COMMAND={slash_command}", |
| 173 | content, |
| 174 | ) |
| 175 | else: |
| 176 | content += f"\nSLACK_SLASH_COMMAND={slash_command}" |
| 177 | |
| 178 | # Write back |
| 179 | with open(VM_ENV_PATH, "w") as f: |
| 180 | f.write(content) |
| 181 |
no test coverage detected