update
This commit is contained in:
+15
-2
@@ -19,6 +19,7 @@ type Function struct {
|
||||
FindAll bool
|
||||
Admin bool
|
||||
Handle func(s im.Sender) interface{}
|
||||
Regex bool
|
||||
}
|
||||
|
||||
var pname = regexp.MustCompile(`/([^/\s]+)`).FindStringSubmatch(os.Args[0])[1]
|
||||
@@ -108,8 +109,20 @@ func initToHandleMessage() {
|
||||
}()
|
||||
}
|
||||
|
||||
func AddCommand(cmd []Function) {
|
||||
functions = append(functions, cmd...)
|
||||
func AddCommand(prefix string, cmds []Function) {
|
||||
for _, cmd := range cmds {
|
||||
if !cmd.Regex {
|
||||
for i := range cmd.Rules {
|
||||
if prefix != "" {
|
||||
cmd.Rules[i] += prefix + `\s+` + cmd.Rules[i]
|
||||
}
|
||||
cmd.Rules[i] = strings.Replace(cmd.Rules[i], " ", `\s+`, -1)
|
||||
cmd.Rules[i] = strings.Replace(cmd.Rules[i], "?", `(\S+)`, -1)
|
||||
cmd.Rules[i] += "^" + cmd.Rules[i] + "$"
|
||||
}
|
||||
}
|
||||
functions = append(functions, cmd)
|
||||
}
|
||||
}
|
||||
|
||||
func handleMessage(sender im.Sender) {
|
||||
|
||||
@@ -31,9 +31,9 @@ type JdCookie struct {
|
||||
var ua = `Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_2 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/6533.18.5 UCBrowser/13.4.2.1122`
|
||||
|
||||
func init() {
|
||||
core.AddCommand([]core.Function{
|
||||
core.AddCommand("ql", []core.Function{
|
||||
{
|
||||
Rules: []string{`^asset\s+(.+)$`, `^查询\s+(.+)$`},
|
||||
Rules: []string{`jd asset ?`},
|
||||
Handle: func(s im.Sender) interface{} {
|
||||
a := s.Get()
|
||||
envs, err := qinglong.GetEnvs("JD_COOKIE")
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
package jdcookie
|
||||
|
||||
func init() {
|
||||
|
||||
}
|
||||
@@ -101,7 +101,6 @@ func init() {
|
||||
Value: f[i],
|
||||
})
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,9 +29,10 @@ type Cron struct {
|
||||
}
|
||||
|
||||
func init() {
|
||||
core.AddCommand([]core.Function{
|
||||
core.AddCommand("ql", []core.Function{
|
||||
{
|
||||
Rules: []string{`^crons$`},
|
||||
Rules: []string{`crons`},
|
||||
Admin: true,
|
||||
Handle: func(_ im.Sender) interface{} {
|
||||
crons, err := GetCrons("")
|
||||
if err != nil {
|
||||
@@ -48,7 +49,8 @@ func init() {
|
||||
},
|
||||
},
|
||||
{
|
||||
Rules: []string{`^cron\s+get\s+([\S]+)$`},
|
||||
Rules: []string{`cron get ?`},
|
||||
Admin: true,
|
||||
Handle: func(s im.Sender) interface{} {
|
||||
name := s.Get()
|
||||
crons, err := GetCrons("")
|
||||
@@ -68,7 +70,8 @@ func init() {
|
||||
},
|
||||
},
|
||||
{
|
||||
Rules: []string{`^cron\s+find\s+([\S]+)$`},
|
||||
Rules: []string{`cron find ?`},
|
||||
Admin: true,
|
||||
Handle: func(s im.Sender) interface{} {
|
||||
name := s.Get()
|
||||
crons, err := GetCrons("")
|
||||
@@ -88,7 +91,8 @@ func init() {
|
||||
},
|
||||
},
|
||||
{
|
||||
Rules: []string{`^cron\s+logs\s+([\S]+)$`},
|
||||
Rules: []string{`cron logs ?`},
|
||||
Admin: true,
|
||||
Handle: func(s im.Sender) interface{} {
|
||||
data, err := GetCronLog(s.Get())
|
||||
if err != nil {
|
||||
|
||||
+14
-7
@@ -24,9 +24,10 @@ type Env struct {
|
||||
}
|
||||
|
||||
func init() {
|
||||
core.AddCommand([]core.Function{
|
||||
core.AddCommand("ql", []core.Function{
|
||||
{
|
||||
Rules: []string{`^envs$`},
|
||||
Rules: []string{`envs`},
|
||||
Admin: true,
|
||||
Handle: func(_ im.Sender) interface{} {
|
||||
envs, err := GetEnvs("")
|
||||
if err != nil {
|
||||
@@ -43,7 +44,8 @@ func init() {
|
||||
},
|
||||
},
|
||||
{
|
||||
Rules: []string{`^env\s+get\s+([\S]+)$`},
|
||||
Rules: []string{`env get ?`},
|
||||
Admin: true,
|
||||
Handle: func(s im.Sender) interface{} {
|
||||
name := s.Get()
|
||||
envs, err := GetEnvs(name)
|
||||
@@ -63,7 +65,8 @@ func init() {
|
||||
},
|
||||
},
|
||||
{
|
||||
Rules: []string{`^env\s+find\s+([\S]+)$`},
|
||||
Rules: []string{`env find ?)`},
|
||||
Admin: true,
|
||||
Handle: func(s im.Sender) interface{} {
|
||||
m := s.Get()
|
||||
envs, err := GetEnvs(m)
|
||||
@@ -81,7 +84,9 @@ func init() {
|
||||
},
|
||||
},
|
||||
{
|
||||
Rules: []string{`^export\s+([^'"=]+)=['"]?([^=]+?)['"]?$`, `^env\s+set\s+([^'"=]+)=['"]?([^=]+?)['"]?$`},
|
||||
Rules: []string{`export ([^'"=]+)=['"]?([^=]+?)['"]?`},
|
||||
Regex: true,
|
||||
Admin: true,
|
||||
Handle: func(s im.Sender) interface{} {
|
||||
e := &Env{
|
||||
Name: s.Get(0),
|
||||
@@ -95,7 +100,8 @@ func init() {
|
||||
},
|
||||
},
|
||||
{
|
||||
Rules: []string{`^env\s+del\s+([\S]+)$`},
|
||||
Rules: []string{`env del ?`},
|
||||
Admin: true,
|
||||
Handle: func(s im.Sender) interface{} {
|
||||
if err := RemEnv(&Env{ID: s.Get()}); err != nil {
|
||||
return err
|
||||
@@ -104,7 +110,8 @@ func init() {
|
||||
},
|
||||
},
|
||||
{
|
||||
Rules: []string{`^env\s+remark\s+([\S]+)\s+([\S]+)$`},
|
||||
Rules: []string{`env remark ? ?`},
|
||||
Admin: true,
|
||||
Handle: func(s im.Sender) interface{} {
|
||||
if err := ModEnv(&Env{ID: s.Get(0), Remarks: s.Get(1)}); err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user