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