SaveRoomScript writes (or overwrites) the JavaScript file for a room. If content is empty the script file is deleted instead.
(roomId int, content string)
| 358 | // SaveRoomScript writes (or overwrites) the JavaScript file for a room. If |
| 359 | // content is empty the script file is deleted instead. |
| 360 | func SaveRoomScript(roomId int, content string) error { |
| 361 | r := LoadRoomTemplate(roomId) |
| 362 | if r == nil { |
| 363 | return fmt.Errorf("room %d not found", roomId) |
| 364 | } |
| 365 | |
| 366 | scriptPath := r.GetScriptPath() |
| 367 | |
| 368 | if content == "" { |
| 369 | if err := os.Remove(scriptPath); err != nil && !os.IsNotExist(err) { |
| 370 | return fmt.Errorf("removing room script: %w", err) |
| 371 | } |
| 372 | return nil |
| 373 | } |
| 374 | |
| 375 | return util.WriteFile(scriptPath, []byte(content), 0644) |
| 376 | } |
| 377 | |
| 378 | type MapperRoomData struct { |
| 379 | RoomId int `json:"RoomId"` |
no test coverage detected