update
This commit is contained in:
+62
-5
@@ -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")
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user