SaveBuffScript writes (or overwrites) the JavaScript file for a buff. If content is empty the script file is deleted instead.
(buffId int, content string)
| 69 | // SaveBuffScript writes (or overwrites) the JavaScript file for a buff. If |
| 70 | // content is empty the script file is deleted instead. |
| 71 | func SaveBuffScript(buffId int, content string) error { |
| 72 | spec := GetBuffSpec(buffId) |
| 73 | if spec == nil { |
| 74 | return fmt.Errorf("buff %d not found", buffId) |
| 75 | } |
| 76 | |
| 77 | scriptPath := spec.GetScriptPath() |
| 78 | |
| 79 | if content == "" { |
| 80 | if err := os.Remove(scriptPath); err != nil && !os.IsNotExist(err) { |
| 81 | return fmt.Errorf("removing buff script: %w", err) |
| 82 | } |
| 83 | return nil |
| 84 | } |
| 85 | |
| 86 | return util.WriteFile(scriptPath, []byte(content), 0644) |
| 87 | } |
no test coverage detected