-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelps.go
More file actions
59 lines (45 loc) · 1 KB
/
helps.go
File metadata and controls
59 lines (45 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"M45HelpBot/cwlog"
"bytes"
"encoding/json"
"fmt"
"os"
)
var helpsList []HelpsListData
type HelpsListData struct {
Name string
Data []helpData
}
func readHelps() bool {
file, err := os.ReadFile(helpsFile)
if err != nil {
cwlog.DoLog(err.Error())
return false
}
err = json.Unmarshal(file, &helpsList)
if err != nil {
cwlog.DoLog("Error: readHelps: Unable to unmashal helps file.")
return false
}
helpsCount := 0
for _, helpsType := range helpsList {
helpsCount += len(helpsType.Data)
}
buf := fmt.Sprintf("Loaded %v helps types, and %v helps.", len(helpsList), helpsCount)
cwlog.DoLog(buf)
return true
}
func writeHelps() {
outbuf := new(bytes.Buffer)
enc := json.NewEncoder(outbuf)
enc.SetIndent("", "\t")
if err := enc.Encode(helpsList); err != nil {
cwlog.DoLog("writeHelps: enc.Encode failure")
return
}
err := os.WriteFile(helpsFile, outbuf.Bytes(), 0755)
if err != nil {
cwlog.DoLog("Error: writeHelps: Unable to write the helps file.")
}
}