MCPcopy Create free account
hub / github.com/GoMudEngine/GoMud / SaveBuffScript

Function SaveBuffScript

internal/buffs/admin.go:71–87  ·  view source on GitHub ↗

SaveBuffScript writes (or overwrites) the JavaScript file for a buff. If content is empty the script file is deleted instead.

(buffId int, content string)

Source from the content-addressed store, hash-verified

69// SaveBuffScript writes (or overwrites) the JavaScript file for a buff. If
70// content is empty the script file is deleted instead.
71func 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}

Callers 1

apiV1PutBuffScriptFunction · 0.92

Calls 4

WriteFileFunction · 0.92
GetBuffSpecFunction · 0.85
GetScriptPathMethod · 0.45
RemoveMethod · 0.45

Tested by

no test coverage detected