x
This commit is contained in:
@@ -206,6 +206,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
return id
|
return id
|
||||||
} else {
|
} else {
|
||||||
|
// {"params":{"user_id":"798731886","message":"2023-06-29 13:44:05","group_id":"178583761"},"action":"send_group_msg"}
|
||||||
params := map[string]interface{}{
|
params := map[string]interface{}{
|
||||||
"group_id": msg[core.CHAT_ID],
|
"group_id": msg[core.CHAT_ID],
|
||||||
"user_id": msg[core.USER_ID],
|
"user_id": msg[core.USER_ID],
|
||||||
|
|||||||
+4
-3
@@ -58,6 +58,7 @@ type Factory struct {
|
|||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
destroid bool
|
destroid bool
|
||||||
errorTimes int
|
errorTimes int
|
||||||
|
Res *Response
|
||||||
}
|
}
|
||||||
|
|
||||||
type Bot [2]string //botplt botid
|
type Bot [2]string //botplt botid
|
||||||
@@ -493,13 +494,13 @@ func (f *Factory) Receive(wt interface{}) *CustomSender {
|
|||||||
sender.details.Content = fmt.Sprint(props[i])
|
sender.details.Content = fmt.Sprint(props[i])
|
||||||
h = true
|
h = true
|
||||||
case "message_id", "messageId":
|
case "message_id", "messageId":
|
||||||
sender.details.MessageID = fmt.Sprint(props[i])
|
sender.details.MessageID = utils.Itoa(props[i])
|
||||||
h = true
|
h = true
|
||||||
case "user_id", "userId":
|
case "user_id", "userId":
|
||||||
sender.details.UserID = fmt.Sprint(props[i])
|
sender.details.UserID = utils.Itoa(props[i])
|
||||||
h = true
|
h = true
|
||||||
case "chat_id", "chatId", "group_id", "groupId", "group_code", "groupCode":
|
case "chat_id", "chatId", "group_id", "groupId", "group_code", "groupCode":
|
||||||
sender.details.ChatID = fmt.Sprint(props[i])
|
sender.details.ChatID = ChatID(props[i])
|
||||||
h = true
|
h = true
|
||||||
case "user_name", "userName":
|
case "user_name", "userName":
|
||||||
sender.details.Username = fmt.Sprint(props[i])
|
sender.details.Username = fmt.Sprint(props[i])
|
||||||
|
|||||||
+1
-1
@@ -395,7 +395,7 @@ func init() {
|
|||||||
var scripts = map[string]string{}
|
var scripts = map[string]string{}
|
||||||
functions := Functions
|
functions := Functions
|
||||||
for _, function := range functions {
|
for _, function := range functions {
|
||||||
if function.UUID != "" && ((len(function.Rules) == 0 && !function.OnStart && !function.Module && function.Http == nil && function.Reply == nil) || function.Carry) {
|
if function.UUID != "" && ((len(function.Rules) == 0 && !function.OnStart && !function.Module && len(function.Https) == 0 && function.Reply == nil) || function.Carry) {
|
||||||
scripts[function.UUID] = function.Title + ".js"
|
scripts[function.UUID] = function.Title + ".js"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,12 +32,12 @@ type Function struct {
|
|||||||
Encrypt bool `json:"encrypt"`
|
Encrypt bool `json:"encrypt"`
|
||||||
OnStart bool `json:"on_start"`
|
OnStart bool `json:"on_start"`
|
||||||
PluginPublisher
|
PluginPublisher
|
||||||
Running bool `json:"running"`
|
Running bool `json:"running"`
|
||||||
Http *Http `json:"-"`
|
Https []*Http `json:"-"`
|
||||||
Reply *Reply `json:"-"`
|
Reply *Reply `json:"-"`
|
||||||
Downloads int `json:"downloads"`
|
Downloads int `json:"downloads"`
|
||||||
HasForm bool `json:"has_form"`
|
HasForm bool `json:"has_form"`
|
||||||
Carry bool `json:"carry"`
|
Carry bool `json:"carry"`
|
||||||
}
|
}
|
||||||
type Filter struct {
|
type Filter struct {
|
||||||
BlackMode bool
|
BlackMode bool
|
||||||
|
|||||||
+4
-4
@@ -272,7 +272,7 @@ func initPlugin(data string, uuid string) (*common.Function, []func(), error) {
|
|||||||
var encrypt bool
|
var encrypt bool
|
||||||
var onStart bool
|
var onStart bool
|
||||||
var origin = "自定义"
|
var origin = "自定义"
|
||||||
var http *common.Http
|
var https = []*common.Http{}
|
||||||
var message *common.Reply
|
var message *common.Reply
|
||||||
var FindAll bool
|
var FindAll bool
|
||||||
var hasForm bool
|
var hasForm bool
|
||||||
@@ -416,10 +416,10 @@ func initPlugin(data string, uuid string) (*common.Function, []func(), error) {
|
|||||||
case "http":
|
case "http":
|
||||||
ss := regexp.MustCompile(`[\S]+`).FindAllString(strings.TrimSpace(res[2]), -1)
|
ss := regexp.MustCompile(`[\S]+`).FindAllString(strings.TrimSpace(res[2]), -1)
|
||||||
if len(ss) == 2 {
|
if len(ss) == 2 {
|
||||||
http = &common.Http{
|
https = append(https, &common.Http{
|
||||||
Path: ss[1],
|
Path: ss[1],
|
||||||
Method: strings.ToUpper(ss[0]),
|
Method: strings.ToUpper(ss[0]),
|
||||||
}
|
})
|
||||||
} else {
|
} else {
|
||||||
console.Warn("http param is not 2")
|
console.Warn("http param is not 2")
|
||||||
}
|
}
|
||||||
@@ -608,7 +608,7 @@ func initPlugin(data string, uuid string) (*common.Function, []func(), error) {
|
|||||||
Origin: origin,
|
Origin: origin,
|
||||||
Running: onStart,
|
Running: onStart,
|
||||||
Reply: message,
|
Reply: message,
|
||||||
Http: http,
|
Https: https,
|
||||||
FindAll: FindAll,
|
FindAll: FindAll,
|
||||||
HasForm: hasForm,
|
HasForm: hasForm,
|
||||||
Carry: carry,
|
Carry: carry,
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ type Request struct {
|
|||||||
uuid string
|
uuid string
|
||||||
bodyData []byte
|
bodyData []byte
|
||||||
_event string
|
_event string
|
||||||
|
Mark interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Request) Body() string {
|
func (r *Request) Body() string {
|
||||||
|
|||||||
@@ -84,6 +84,12 @@ func (r *Response) Json(ps ...interface{}) *Response {
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *Response) Close() {
|
||||||
|
if r.conn != nil {
|
||||||
|
r.conn.Close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (r *Response) Header(str, value string) *Response {
|
func (r *Response) Header(str, value string) *Response {
|
||||||
r.c.Header(str, value)
|
r.c.Header(str, value)
|
||||||
return r
|
return r
|
||||||
|
|||||||
+15
-11
@@ -134,20 +134,24 @@ func initWeb() {
|
|||||||
c: c,
|
c: c,
|
||||||
}
|
}
|
||||||
for _, function := range Functions {
|
for _, function := range Functions {
|
||||||
if function.Http != nil {
|
if len(function.Https) != 0 {
|
||||||
path := function.Http.Path
|
for _, http := range function.Https {
|
||||||
method := function.Http.Method
|
path := http.Path
|
||||||
if c.Request.URL.Path == path && c.Request.Method == method {
|
method := http.Method
|
||||||
req.handled = true
|
if c.Request.URL.Path == path && c.Request.Method == method {
|
||||||
function.Handle(&Faker{
|
req.handled = true
|
||||||
Type: "*",
|
function.Handle(&Faker{
|
||||||
}, func(vm *goja.Runtime) {
|
Type: "*",
|
||||||
vm.Set("res", res)
|
}, func(vm *goja.Runtime) {
|
||||||
vm.Set("req", req)
|
vm.Set("res", res)
|
||||||
})
|
vm.Set("req", req)
|
||||||
|
})
|
||||||
|
goto HELL
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
HELL:
|
||||||
|
|
||||||
if req.handled {
|
if req.handled {
|
||||||
if res.isRedirect {
|
if res.isRedirect {
|
||||||
|
|||||||
+58
-44
@@ -21,57 +21,71 @@ func IsWebSocketRequest(req *http.Request) bool {
|
|||||||
|
|
||||||
func handleWebsocket(c *gin.Context) {
|
func handleWebsocket(c *gin.Context) {
|
||||||
for _, function := range Functions {
|
for _, function := range Functions {
|
||||||
if function.Http != nil {
|
if len(function.Https) != 0 {
|
||||||
path := function.Http.Path
|
for _, h := range function.Https {
|
||||||
method := function.Http.Method
|
path := h.Path
|
||||||
if c.Request.URL.Path == path && strings.HasPrefix(method, "W") {
|
method := h.Method
|
||||||
// connect
|
if c.Request.URL.Path == path && strings.HasPrefix(method, "W") {
|
||||||
var req = &Request{
|
// connect
|
||||||
c: c,
|
var req = &Request{
|
||||||
// uuid: uuid,
|
c: c,
|
||||||
}
|
// uuid: uuid,
|
||||||
var res = &Response{
|
|
||||||
c: c,
|
|
||||||
}
|
|
||||||
req._event = "connect"
|
|
||||||
function.Handle(&Faker{
|
|
||||||
Type: "*",
|
|
||||||
}, func(vm *goja.Runtime) {
|
|
||||||
vm.Set("res", res)
|
|
||||||
vm.Set("req", req)
|
|
||||||
})
|
|
||||||
// message
|
|
||||||
var upGrader = websocket.Upgrader{
|
|
||||||
CheckOrigin: func(r *http.Request) bool {
|
|
||||||
return true
|
|
||||||
},
|
|
||||||
}
|
|
||||||
ws, err := upGrader.Upgrade(c.Writer, c.Request, nil)
|
|
||||||
if err != nil {
|
|
||||||
c.Writer.Write([]byte(err.Error()))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
for {
|
|
||||||
_, data, err := ws.ReadMessage()
|
|
||||||
if err != nil { // disconnect
|
|
||||||
req._event = "disconnect"
|
|
||||||
function.Handle(&Faker{
|
|
||||||
Type: "*",
|
|
||||||
}, func(vm *goja.Runtime) {
|
|
||||||
vm.Set("res", res)
|
|
||||||
vm.Set("req", req)
|
|
||||||
})
|
|
||||||
ws.Close()
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
req.bodyData = data
|
var res = &Response{
|
||||||
req._event = "message"
|
c: c,
|
||||||
|
}
|
||||||
|
req._event = "connect"
|
||||||
function.Handle(&Faker{
|
function.Handle(&Faker{
|
||||||
Type: "*",
|
Type: "*",
|
||||||
}, func(vm *goja.Runtime) {
|
}, func(vm *goja.Runtime) {
|
||||||
vm.Set("res", res)
|
vm.Set("res", res)
|
||||||
vm.Set("req", req)
|
vm.Set("req", req)
|
||||||
})
|
})
|
||||||
|
// message
|
||||||
|
var upGrader = websocket.Upgrader{
|
||||||
|
CheckOrigin: func(r *http.Request) bool {
|
||||||
|
return true
|
||||||
|
},
|
||||||
|
}
|
||||||
|
ws, err := upGrader.Upgrade(c.Writer, c.Request, nil)
|
||||||
|
if err != nil {
|
||||||
|
c.Writer.Write([]byte(err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
res.conn = ws
|
||||||
|
for {
|
||||||
|
_, data, err := ws.ReadMessage()
|
||||||
|
if err != nil { // disconnect
|
||||||
|
req._event = "disconnect"
|
||||||
|
for _, f2 := range Functions {
|
||||||
|
if f2.UUID == function.UUID {
|
||||||
|
function = f2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function.Handle(&Faker{
|
||||||
|
Type: "*",
|
||||||
|
}, func(vm *goja.Runtime) {
|
||||||
|
vm.Set("res", res)
|
||||||
|
vm.Set("req", req)
|
||||||
|
})
|
||||||
|
ws.Close()
|
||||||
|
break
|
||||||
|
}
|
||||||
|
req.bodyData = data
|
||||||
|
req._event = "message"
|
||||||
|
for _, f2 := range Functions {
|
||||||
|
if f2.UUID == function.UUID {
|
||||||
|
function = f2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function.Handle(&Faker{
|
||||||
|
Type: "*",
|
||||||
|
}, func(vm *goja.Runtime) {
|
||||||
|
vm.Set("res", res)
|
||||||
|
vm.Set("req", req)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
_ "github.com/cdle/sillyplus/adapters/qq"
|
// _ "github.com/cdle/sillyplus/adapters/qq"
|
||||||
"github.com/cdle/sillyplus/adapters/web"
|
"github.com/cdle/sillyplus/adapters/web"
|
||||||
"github.com/cdle/sillyplus/core"
|
"github.com/cdle/sillyplus/core"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user