💩👌 make lint happy

This commit is contained in:
fumiama
2021-08-06 17:44:48 +08:00
parent e477e0b452
commit ce406d8f55
10 changed files with 66 additions and 57 deletions

View File

@@ -2,6 +2,7 @@
package diana
import (
fmt "fmt"
"math/rand"
"time"
@@ -71,6 +72,9 @@ func init() {
// 增加小作文
zero.OnRegex(`^教你一篇小作文(.*)$`, zero.AdminPermission).
Handle(func(ctx *zero.Ctx) {
addText(ctx.State["regex_matched"].([]string)[1])
err := addText(ctx.State["regex_matched"].([]string)[1])
if err != nil {
ctx.Send(fmt.Sprintf("ERROR: %v", err))
}
})
}

View File

@@ -23,23 +23,27 @@ func init() {
if err != nil {
panic(err)
}
loadText()
array = compo.Array
if loadText() == nil {
array = compo.Array
}
}()
}
func loadText() {
func loadText() error {
if _, err := os.Stat(pbfile); err == nil || os.IsExist(err) {
f, err := os.Open(pbfile)
if err == nil {
data, err1 := io.ReadAll(f)
if err1 == nil {
if len(data) > 0 {
compo.Unmarshal(data)
return compo.Unmarshal(data)
}
}
return err1
}
return err
}
return nil
}
func addText(txt string) error {