diff --git a/.gitignore b/.gitignore index fcac4f2..d7b071c 100644 --- a/.gitignore +++ b/.gitignore @@ -12,5 +12,4 @@ data dwz replies qinglongs -sets.conf -xiaoai.go \ No newline at end of file +sets.conf \ No newline at end of file diff --git a/core/xiaoai.go b/core/xiaoai.go new file mode 100644 index 0000000..8e36fe6 --- /dev/null +++ b/core/xiaoai.go @@ -0,0 +1,51 @@ +package core + +import ( + "fmt" + "time" + + "github.com/beego/beego/v2/client/httplib" +) + +func init() { + AddCommand("", []Function{ + { + 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() + if str == "" { + str = "暂时无法回复。" + } + return str + } + msg := s.Get() + if msg == "对话模式" { + stop := false + for { + if stop { + break + } + s.Await(s, func(s2 Sender) interface{} { + msg := s2.Get() + if msg == "闭嘴" { + stop = true + } + return reply(msg) + }, `[\s\S]*`, time.Duration(time.Second*300)) + } + } + if msg == "" { + msg = "小爱" + } + return name() + }, + }, + }) +}