diff --git a/core/xiaoai.go b/core/game.go similarity index 50% rename from core/xiaoai.go rename to core/game.go index e5c7a84..f632e51 100644 --- a/core/xiaoai.go +++ b/core/game.go @@ -56,5 +56,50 @@ func init() { return reply(msg) }, }, + // { + // Rules: []string{ + // "^挑战古诗词$", + // }, + // Handle: func(s Sender) interface{} { + // api := sillyGirl.Get("小爱同学") + // if api == "" { + // return "未设置小同学api" + // } + // reply := func(str string) string { + // str, _ = httplib.Get(fmt.Sprintf(api, str)).String() + // // s.Reply(str) + // if gjson := sillyGirl.Get("小爱同学gjson"); gjson != "" { + // str, _ = jsonparser.GetString([]byte(str), strings.Split(gjson, ".")...) + // } + // if str == "" { + // str = "暂时无法回复。" + // } + // return str + // } + // msg := s.Get() + // msg = strings.Trim(msg, " ") + // if strings.Contains(msg, "对话模式") { + // stop := false + // s.Reply(reply("小爱")) + // for { + // if stop { + // return nil + // } + // s.Await(s, func(s2 Sender) interface{} { + // msg := s2.GetContent() + // msg = strings.Trim(msg, " ") + // if strings.Contains(msg, "闭嘴") { + // stop = true + // } + // return reply(msg) + // }, `[\s\S]*`, time.Duration(time.Second*5000)) + // } + // } + // if msg == "" { + // msg = "小爱" + // } + // return reply(msg) + // }, + // }, }) } diff --git a/develop/qinglong/env.go b/develop/qinglong/env.go index 1bd56b1..22b3c88 100644 --- a/develop/qinglong/env.go +++ b/develop/qinglong/env.go @@ -2,6 +2,11 @@ package qinglong import ( "errors" + "fmt" + "strings" + "time" + + "github.com/cdle/sillyGirl/core" ) type EnvResponse struct { @@ -10,11 +15,13 @@ type EnvResponse struct { } type Env struct { - Value string `json:"value,omitempty"` - ID string `json:"_id,omitempty"` - Status int `json:"status,omitempty"` - Name string `json:"name,omitempty"` - Remarks string `json:"remarks,omitempty"` + Value string `json:"value,omitempty"` + ID string `json:"_id,omitempty"` + Status int `json:"status,omitempty"` + Name string `json:"name,omitempty"` + Remarks string `json:"remarks,omitempty"` + Timestamp string `json:"timestamp,omitempty"` + Created int64 `json:"created,omitempty"` } func GetEnv(id string) (*Env, error) { @@ -93,3 +100,53 @@ func AddEnv(e Env) error { func RemEnv(e *Env) error { return Config.Req(DELETE, ENVS, []byte(`["`+e.ID+`"]`)) } + +func init() { + core.AddCommand("ql", []core.Function{ + { + Rules: []string{`cookie status`}, + Admin: true, + Handle: func(_ core.Sender) interface{} { + type Count struct { + Total int + Disable int + TodayCreate int + TodayDisable int + TodayUpdate int + } + envs, err := GetEnvs("") + if err != nil { + return err + } + today := time.Now() + var cookies = map[string]*Count{} + for _, env := range envs { + var c *Count + if _, ok := cookies[env.Name]; !ok { + cookies[env.Name] = &Count{} + } + c = cookies[env.Name] + c.Total++ + if strings.Contains(env.Timestamp, fmt.Sprintf(`%s %s`, today.Month().String()[0:3], today.Format("02 2006"))) { + if env.Status != 0 { + c.TodayDisable++ + } else { + c.TodayUpdate++ + } + } + if env.Status != 0 { + c.Disable++ + } + if time.Unix(env.Created, 0).Format("2006-01-02") == today.Format("2006-01-02") { + c.TodayCreate++ + } + } + ss := []string{} + for name, c := range cookies { + ss = append(ss, fmt.Sprintf(`%s 今日新增%d,今日更新%d,今日失效%d,总数%d,有效%d,无效%d`, name, c.TodayCreate, c.TodayUpdate, c.TodayDisable, c.Total, c.Total-c.Disable, c.Disable)) + } + return strings.Join(ss, "\n") + }, + }, + }) +}