This commit is contained in:
cdle
2023-07-03 19:12:43 +08:00
parent f0ce2ac5d5
commit 437a31a6b8
5 changed files with 69 additions and 122 deletions
+6
View File
@@ -523,6 +523,12 @@ running(): boolean; //服务是否运行
uuid(): string; //生成uuid uuid(): string; //生成uuid
``` ```
### 拓展 CQ 码命令
[CQ:delete,id=message_id]
[CQ:kick,user_id,chat_id,forever=true]
[CQ:ban,user_id,chat_id,duration=0]
### 项目赞助 ### 项目赞助
打开微信扫一扫,深入了解作者~ 打开微信扫一扫,深入了解作者~
+33 -33
View File
@@ -152,39 +152,39 @@ func init() {
adapter := &core.Factory{} adapter := &core.Factory{}
adapter.Init("qq", botID, nil) adapter.Init("qq", botID, nil)
defer adapter.Destroy() defer adapter.Destroy()
adapter.SetGroupKick(func(uid string, gid string, reject_add_request bool) bool { // adapter.SetGroupKick(func(uid string, gid string, reject_add_request bool) bool {
qqcon.WriteJSON(CallApi{ // qqcon.WriteJSON(CallApi{
Action: "set_group_kick", // Action: "set_group_kick",
Params: map[string]interface{}{ // Params: map[string]interface{}{
"group_id": utils.Int(gid), // "group_id": utils.Int(gid),
"user_id": utils.Int(uid), // "user_id": utils.Int(uid),
"reject_add_request": reject_add_request, // "reject_add_request": reject_add_request,
}, // },
}) // })
return true // return true
}) // })
adapter.SetGroupBan(func(uid string, gid string, duration int) bool { // adapter.SetGroupBan(func(uid string, gid string, duration int) bool {
qqcon.WriteJSON(CallApi{ // qqcon.WriteJSON(CallApi{
Action: "set_group_ban", // Action: "set_group_ban",
Params: map[string]interface{}{ // Params: map[string]interface{}{
"group_id": utils.Int(gid), // "group_id": utils.Int(gid),
"user_id": utils.Int(uid), // "user_id": utils.Int(uid),
"duration": duration, // "duration": duration,
}, // },
}) // })
return true // return true
}) // })
adapter.SetGroupUnban(func(uid string, gid string) bool { // adapter.SetGroupUnban(func(uid string, gid string) bool {
qqcon.WriteJSON(CallApi{ // qqcon.WriteJSON(CallApi{
Action: "set_group_ban", // Action: "set_group_ban",
Params: map[string]interface{}{ // Params: map[string]interface{}{
"group_id": utils.Int(gid), // "group_id": utils.Int(gid),
"user_id": utils.Int(uid), // "user_id": utils.Int(uid),
"duration": 1, // "duration": 1,
}, // },
}) // })
return true // return true
}) // })
adapter.SetReplyHandler(func(msg map[string]interface{}) string { adapter.SetReplyHandler(func(msg map[string]interface{}) string {
if debug { if debug {
logs.Debug("QQ发送消息:", string(utils.JsonMarshal(msg))) logs.Debug("QQ发送消息:", string(utils.JsonMarshal(msg)))
+24 -88
View File
@@ -47,27 +47,23 @@ type GMsgChan struct {
} }
type Factory struct { type Factory struct {
botid string botid string
botplt string botplt string
uuid string uuid string
msgChan chan MsgChan msgChan chan MsgChan
demo *CustomSender demo *CustomSender
reply func(map[string]interface{}) string reply func(map[string]interface{}) string
lm chan bool lm chan bool
nm int64 nm int64
recallMessage func(interface{}) bool isAdmin func(string) bool
groupKick func(uid string, gid string, reject_add_request bool) bool vm *goja.Runtime
groupBan func(uid string, gid string, duration int) bool ctx context.Context
groupUnban func(uid string, gid string) bool cancel context.CancelFunc
isAdmin func(string) bool destroid bool
vm *goja.Runtime errorTimes int
ctx context.Context Res *Response
cancel context.CancelFunc umod bool //类似订阅号一对一被动消息模式
destroid bool gmsgChan sync.Map
errorTimes int
Res *Response
umod bool //类似订阅号一对一被动消息模式
gmsgChan sync.Map
} }
type Bot [2]string //botplt botid type Bot [2]string //botplt botid
@@ -507,54 +503,6 @@ func (f *Factory) Send(function func(map[string]interface{}) string) {
f.SetReplyHandler(function) f.SetReplyHandler(function)
} }
func (f *Factory) SetRecallMessage(function func(interface{}) bool) {
f.recallMessage = func(i interface{}) bool {
defer func() {
err := recover()
if err != nil {
pluginConsole(f.uuid).Error("Sender(\""+f.botplt+"\").recall error:", err)
}
}()
return function(i)
}
}
func (f *Factory) SetGroupKick(function func(uid string, gid string, reject_add_request bool) bool) {
f.groupKick = func(uid string, gid string, reject_add_request bool) bool {
defer func() {
err := recover()
if err != nil {
pluginConsole(f.uuid).Error("Sender(\""+f.botplt+"\").GroupKick error:", err)
}
}()
return function(uid, gid, reject_add_request)
}
}
func (f *Factory) SetGroupBan(function func(uid string, gid string, duration int) bool) {
f.groupBan = func(uid string, gid string, duration int) bool {
defer func() {
err := recover()
if err != nil {
pluginConsole(f.uuid).Error("Sender(\""+f.botplt+"\").SetGroupBan error:", err)
}
}()
return function(uid, gid, duration)
}
}
func (f *Factory) SetGroupUnban(function func(uid string, gid string) bool) {
f.groupUnban = func(uid string, gid string) bool {
defer func() {
err := recover()
if err != nil {
pluginConsole(f.uuid).Error("Sender(\""+f.botplt+"\").SetgroupUnban error:", err)
}
}()
return function(uid, gid)
}
}
func (f *Factory) SetIsAdmin(function func(string) bool) { func (f *Factory) SetIsAdmin(function func(string) bool) {
f.isAdmin = func(uid string) bool { f.isAdmin = func(uid string) bool {
defer func() { defer func() {
@@ -576,7 +524,7 @@ func (f *Factory) Receive(wt interface{}) *CustomSender {
h := false h := false
switch strings.ToLower(i) { switch strings.ToLower(i) {
case "content": case "content":
sender.details.Content = fmt.Sprint(props[i]) sender.details.Content = strings.TrimSpace(fmt.Sprint(props[i]))
h = true h = true
case "message_id", "messageId": case "message_id", "messageId":
sender.details.MessageID = utils.Itoa(props[i]) sender.details.MessageID = utils.Itoa(props[i])
@@ -783,21 +731,18 @@ func (sender *CustomSender) Copy() common.Sender {
} }
func (sender *CustomSender) RecallMessage(ps ...interface{}) error { func (sender *CustomSender) RecallMessage(ps ...interface{}) error {
if sender.f.recallMessage == nil {
return nil
}
for _, p := range ps { for _, p := range ps {
switch p := p.(type) { switch p := p.(type) {
case string: case string:
sender.f.recallMessage(p) sender.Reply(mystr.BuildCQCode("delete", H{"id": p}, ""))
case []string: case []string:
for _, v := range p { for _, v := range p {
sender.f.recallMessage(v) sender.Reply(mystr.BuildCQCode("delete", H{"id": v}, ""))
} }
case [][]string: case [][]string:
for _, v := range p { for _, v := range p {
for _, v2 := range v { for _, v2 := range v {
sender.f.recallMessage(v2) sender.Reply(mystr.BuildCQCode("delete", H{"id": v2}, ""))
} }
} }
} }
@@ -806,24 +751,15 @@ func (sender *CustomSender) RecallMessage(ps ...interface{}) error {
} }
func (sender *CustomSender) GroupKick(uid string, reject_add_request bool) { func (sender *CustomSender) GroupKick(uid string, reject_add_request bool) {
if sender.f.groupKick == nil { sender.Reply(mystr.BuildCQCode("kick", H{"user_id": uid, "chat_id": sender.GetChatID(), "forever": reject_add_request}, ""))
return
}
sender.f.groupKick(uid, sender.GetChatID(), reject_add_request)
} }
func (sender *CustomSender) GroupBan(uid string, duration int) { func (sender *CustomSender) GroupBan(uid string, duration int) {
if sender.f.groupBan == nil { sender.Reply(mystr.BuildCQCode("ban", H{"user_id": uid, "chat_id": sender.GetChatID(), "duration": duration}, ""))
return
}
sender.f.groupBan(uid, sender.GetChatID(), duration)
} }
func (sender *CustomSender) GroupUnban(uid string) { func (sender *CustomSender) GroupUnban(uid string) {
if sender.f.groupUnban == nil { sender.Reply(mystr.BuildCQCode("ban", H{"user_id": uid, "chat_id": sender.GetChatID(), "duration": 0}, ""))
return
}
sender.f.groupUnban(uid, sender.GetChatID())
} }
func (sender *CustomSender) IsAdmin() bool { func (sender *CustomSender) IsAdmin() bool {
+2 -1
View File
@@ -1,6 +1,7 @@
package core package core
import ( import (
"errors"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"strings" "strings"
@@ -26,7 +27,7 @@ func MakeResponseObject(vm *goja.Runtime, resp *http.Response, responseType stri
var v interface{} var v interface{}
err := json.Unmarshal(data, &v) err := json.Unmarshal(data, &v)
if err != nil { ///// if err != nil { /////
return obj, err return obj, errors.New("请求返回数据不是json格式:" + string(data))
} else { } else {
body = v body = v
} }
+4
View File
@@ -16,10 +16,14 @@ import (
"github.com/cdle/sillyplus/utils" "github.com/cdle/sillyplus/utils"
) )
var mystr = &Strings{}
type Strings struct { type Strings struct {
UUID string UUID string
} }
type H map[string]interface{}
func (sender *Strings) Diff(a, b []interface{}) []interface{} { func (sender *Strings) Diff(a, b []interface{}) []interface{} {
m := make(map[interface{}]bool) m := make(map[interface{}]bool)
c := make([]interface{}, 0) c := make([]interface{}, 0)