mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-06-30 11:53:25 +00:00
Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
470efa07ab | |||
b7572f8d2c | |||
c9a914b5d5 | |||
51696e8054 | |||
a6bcd96415 | |||
08694f5ae8 | |||
8c71dbff68 | |||
568b0e479f | |||
d1da08a376 | |||
5768c61bc7 | |||
864120d3fe | |||
99b414530a | |||
4820eb2fec | |||
9af61a336b |
114
coolq/api.go
114
coolq/api.go
@ -34,8 +34,11 @@ func (bot *CQBot) CQGetFriendList() MSG {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// https://cqhttp.cc/docs/4.15/#/API?id=get_group_list-%E8%8E%B7%E5%8F%96%E7%BE%A4%E5%88%97%E8%A1%A8
|
// https://cqhttp.cc/docs/4.15/#/API?id=get_group_list-%E8%8E%B7%E5%8F%96%E7%BE%A4%E5%88%97%E8%A1%A8
|
||||||
func (bot *CQBot) CQGetGroupList() MSG {
|
func (bot *CQBot) CQGetGroupList(noCache bool) MSG {
|
||||||
var gs []MSG
|
var gs []MSG
|
||||||
|
if noCache {
|
||||||
|
_ = bot.Client.ReloadGroupList()
|
||||||
|
}
|
||||||
for _, g := range bot.Client.GroupList {
|
for _, g := range bot.Client.GroupList {
|
||||||
gs = append(gs, MSG{
|
gs = append(gs, MSG{
|
||||||
"group_id": g.Code,
|
"group_id": g.Code,
|
||||||
@ -96,11 +99,25 @@ func (bot *CQBot) CQGetGroupMemberInfo(groupId, userId int64, noCache bool) MSG
|
|||||||
}
|
}
|
||||||
|
|
||||||
// https://cqhttp.cc/docs/4.15/#/API?id=send_group_msg-%E5%8F%91%E9%80%81%E7%BE%A4%E6%B6%88%E6%81%AF
|
// https://cqhttp.cc/docs/4.15/#/API?id=send_group_msg-%E5%8F%91%E9%80%81%E7%BE%A4%E6%B6%88%E6%81%AF
|
||||||
func (bot *CQBot) CQSendGroupMessage(groupId int64, i interface{}) MSG {
|
func (bot *CQBot) CQSendGroupMessage(groupId int64, i interface{}, autoEscape bool) MSG {
|
||||||
var str string
|
var str string
|
||||||
|
fixAt := func(elem []message.IMessageElement) {
|
||||||
|
for _, e := range elem {
|
||||||
|
if at, ok := e.(*message.AtElement); ok && at.Target != 0 {
|
||||||
|
at.Display = "@" + func() string {
|
||||||
|
mem := bot.Client.FindGroup(groupId).FindMember(at.Target)
|
||||||
|
if mem != nil {
|
||||||
|
return mem.DisplayName()
|
||||||
|
}
|
||||||
|
return strconv.FormatInt(at.Target, 10)
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if m, ok := i.(gjson.Result); ok {
|
if m, ok := i.(gjson.Result); ok {
|
||||||
if m.Type == gjson.JSON {
|
if m.Type == gjson.JSON {
|
||||||
elem := bot.ConvertObjectMessage(m, true)
|
elem := bot.ConvertObjectMessage(m, true)
|
||||||
|
fixAt(elem)
|
||||||
mid := bot.SendGroupMessage(groupId, &message.SendingMessage{Elements: elem})
|
mid := bot.SendGroupMessage(groupId, &message.SendingMessage{Elements: elem})
|
||||||
if mid == -1 {
|
if mid == -1 {
|
||||||
return Failed(100)
|
return Failed(100)
|
||||||
@ -113,26 +130,19 @@ func (bot *CQBot) CQSendGroupMessage(groupId int64, i interface{}) MSG {
|
|||||||
}
|
}
|
||||||
return m.Raw
|
return m.Raw
|
||||||
}()
|
}()
|
||||||
}
|
} else if s, ok := i.(string); ok {
|
||||||
if s, ok := i.(string); ok {
|
|
||||||
str = s
|
str = s
|
||||||
}
|
}
|
||||||
if str == "" {
|
if str == "" {
|
||||||
return Failed(100)
|
return Failed(100)
|
||||||
}
|
}
|
||||||
elem := bot.ConvertStringMessage(str, true)
|
var elem []message.IMessageElement
|
||||||
// fix at display
|
if autoEscape {
|
||||||
for _, e := range elem {
|
elem = append(elem, message.NewText(str))
|
||||||
if at, ok := e.(*message.AtElement); ok && at.Target != 0 {
|
} else {
|
||||||
at.Display = "@" + func() string {
|
elem = bot.ConvertStringMessage(str, true)
|
||||||
mem := bot.Client.FindGroup(groupId).FindMember(at.Target)
|
|
||||||
if mem != nil {
|
|
||||||
return mem.DisplayName()
|
|
||||||
}
|
|
||||||
return strconv.FormatInt(at.Target, 10)
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
fixAt(elem)
|
||||||
mid := bot.SendGroupMessage(groupId, &message.SendingMessage{Elements: elem})
|
mid := bot.SendGroupMessage(groupId, &message.SendingMessage{Elements: elem})
|
||||||
if mid == -1 {
|
if mid == -1 {
|
||||||
return Failed(100)
|
return Failed(100)
|
||||||
@ -211,7 +221,7 @@ func (bot *CQBot) CQSendGroupForwardMessage(groupId int64, m gjson.Result) MSG {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// https://cqhttp.cc/docs/4.15/#/API?id=send_private_msg-%E5%8F%91%E9%80%81%E7%A7%81%E8%81%8A%E6%B6%88%E6%81%AF
|
// https://cqhttp.cc/docs/4.15/#/API?id=send_private_msg-%E5%8F%91%E9%80%81%E7%A7%81%E8%81%8A%E6%B6%88%E6%81%AF
|
||||||
func (bot *CQBot) CQSendPrivateMessage(userId int64, i interface{}) MSG {
|
func (bot *CQBot) CQSendPrivateMessage(userId int64, i interface{}, autoEscape bool) MSG {
|
||||||
var str string
|
var str string
|
||||||
if m, ok := i.(gjson.Result); ok {
|
if m, ok := i.(gjson.Result); ok {
|
||||||
if m.Type == gjson.JSON {
|
if m.Type == gjson.JSON {
|
||||||
@ -228,14 +238,18 @@ func (bot *CQBot) CQSendPrivateMessage(userId int64, i interface{}) MSG {
|
|||||||
}
|
}
|
||||||
return m.Raw
|
return m.Raw
|
||||||
}()
|
}()
|
||||||
}
|
} else if s, ok := i.(string); ok {
|
||||||
if s, ok := i.(string); ok {
|
|
||||||
str = s
|
str = s
|
||||||
}
|
}
|
||||||
if str == "" {
|
if str == "" {
|
||||||
return Failed(100)
|
return Failed(100)
|
||||||
}
|
}
|
||||||
elem := bot.ConvertStringMessage(str, false)
|
var elem []message.IMessageElement
|
||||||
|
if autoEscape {
|
||||||
|
elem = append(elem, message.NewText(str))
|
||||||
|
} else {
|
||||||
|
elem = bot.ConvertStringMessage(str, false)
|
||||||
|
}
|
||||||
mid := bot.SendPrivateMessage(userId, &message.SendingMessage{Elements: elem})
|
mid := bot.SendPrivateMessage(userId, &message.SendingMessage{Elements: elem})
|
||||||
if mid == -1 {
|
if mid == -1 {
|
||||||
return Failed(100)
|
return Failed(100)
|
||||||
@ -365,6 +379,61 @@ func (bot *CQBot) CQDeleteMessage(messageId int32) MSG {
|
|||||||
return OK(nil)
|
return OK(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_group_honor_info-%E8%8E%B7%E5%8F%96%E7%BE%A4%E8%8D%A3%E8%AA%89%E4%BF%A1%E6%81%AF
|
||||||
|
func (bot *CQBot) CQGetGroupHonorInfo(groupId int64, t string) MSG {
|
||||||
|
msg := MSG{"group_id": groupId}
|
||||||
|
convertMem := func(memList []client.HonorMemberInfo) (ret []MSG) {
|
||||||
|
for _, mem := range memList {
|
||||||
|
ret = append(ret, MSG{
|
||||||
|
"user_id": mem.Uin,
|
||||||
|
"nickname": mem.Name,
|
||||||
|
"avatar": mem.Avatar,
|
||||||
|
"description": mem.Desc,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if t == "talkative" || t == "all" {
|
||||||
|
if honor, err := bot.Client.GetGroupHonorInfo(groupId, client.Talkative); err == nil {
|
||||||
|
if honor.CurrentTalkative.Uin != 0 {
|
||||||
|
msg["current_talkative"] = MSG{
|
||||||
|
"user_id": honor.CurrentTalkative.Uin,
|
||||||
|
"nickname": honor.CurrentTalkative.Name,
|
||||||
|
"avatar": honor.CurrentTalkative.Avatar,
|
||||||
|
"day_count": honor.CurrentTalkative.DayCount,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
msg["talkative_list"] = convertMem(honor.TalkativeList)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if t == "performer" || t == "all" {
|
||||||
|
if honor, err := bot.Client.GetGroupHonorInfo(groupId, client.Performer); err == nil {
|
||||||
|
msg["performer_lis"] = convertMem(honor.ActorList)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if t == "legend" || t == "all" {
|
||||||
|
if honor, err := bot.Client.GetGroupHonorInfo(groupId, client.Legend); err == nil {
|
||||||
|
msg["legend_list"] = convertMem(honor.LegendList)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if t == "strong_newbie" || t == "all" {
|
||||||
|
if honor, err := bot.Client.GetGroupHonorInfo(groupId, client.StrongNewbie); err == nil {
|
||||||
|
msg["strong_newbie_list"] = convertMem(honor.StrongNewbieList)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if t == "emotion" || t == "all" {
|
||||||
|
if honor, err := bot.Client.GetGroupHonorInfo(groupId, client.Emotion); err == nil {
|
||||||
|
msg["emotion_list"] = convertMem(honor.EmotionList)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return OK(msg)
|
||||||
|
}
|
||||||
|
|
||||||
// https://cqhttp.cc/docs/4.15/#/API?id=-handle_quick_operation-%E5%AF%B9%E4%BA%8B%E4%BB%B6%E6%89%A7%E8%A1%8C%E5%BF%AB%E9%80%9F%E6%93%8D%E4%BD%9C
|
// https://cqhttp.cc/docs/4.15/#/API?id=-handle_quick_operation-%E5%AF%B9%E4%BA%8B%E4%BB%B6%E6%89%A7%E8%A1%8C%E5%BF%AB%E9%80%9F%E6%93%8D%E4%BD%9C
|
||||||
// https://github.com/richardchien/coolq-http-api/blob/master/src/cqhttp/plugins/web/http.cpp#L376
|
// https://github.com/richardchien/coolq-http-api/blob/master/src/cqhttp/plugins/web/http.cpp#L376
|
||||||
func (bot *CQBot) CQHandleQuickOperation(context, operation gjson.Result) MSG {
|
func (bot *CQBot) CQHandleQuickOperation(context, operation gjson.Result) MSG {
|
||||||
@ -374,6 +443,7 @@ func (bot *CQBot) CQHandleQuickOperation(context, operation gjson.Result) MSG {
|
|||||||
msgType := context.Get("message_type").Str
|
msgType := context.Get("message_type").Str
|
||||||
reply := operation.Get("reply")
|
reply := operation.Get("reply")
|
||||||
if reply.Exists() {
|
if reply.Exists() {
|
||||||
|
autoEscape := global.EnsureBool(operation.Get("auto_escape"), false)
|
||||||
/*
|
/*
|
||||||
at := true
|
at := true
|
||||||
if operation.Get("at_sender").Exists() {
|
if operation.Get("at_sender").Exists() {
|
||||||
@ -382,10 +452,10 @@ func (bot *CQBot) CQHandleQuickOperation(context, operation gjson.Result) MSG {
|
|||||||
*/
|
*/
|
||||||
// TODO: 处理at字段
|
// TODO: 处理at字段
|
||||||
if msgType == "group" {
|
if msgType == "group" {
|
||||||
bot.CQSendGroupMessage(context.Get("group_id").Int(), reply)
|
bot.CQSendGroupMessage(context.Get("group_id").Int(), reply, autoEscape)
|
||||||
}
|
}
|
||||||
if msgType == "private" {
|
if msgType == "private" {
|
||||||
bot.CQSendPrivateMessage(context.Get("user_id").Int(), reply)
|
bot.CQSendPrivateMessage(context.Get("user_id").Int(), reply, autoEscape)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if msgType == "group" {
|
if msgType == "group" {
|
||||||
|
16
coolq/bot.go
16
coolq/bot.go
@ -64,6 +64,19 @@ func NewQQBot(cli *client.QQClient, conf *global.JsonConfig) *CQBot {
|
|||||||
bot.Client.OnNewFriendAdded(bot.friendAddedEvent)
|
bot.Client.OnNewFriendAdded(bot.friendAddedEvent)
|
||||||
bot.Client.OnGroupInvited(bot.groupInvitedEvent)
|
bot.Client.OnGroupInvited(bot.groupInvitedEvent)
|
||||||
bot.Client.OnUserWantJoinGroup(bot.groupJoinReqEvent)
|
bot.Client.OnUserWantJoinGroup(bot.groupJoinReqEvent)
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
time.Sleep(time.Second * 5)
|
||||||
|
bot.dispatchEventMessage(MSG{
|
||||||
|
"time": time.Now().Unix(),
|
||||||
|
"self_id": bot.Client.Uin,
|
||||||
|
"post_type": "meta_event",
|
||||||
|
"meta_event_type": "heartbeat",
|
||||||
|
"status": nil,
|
||||||
|
"interval": 5000,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}()
|
||||||
return bot
|
return bot
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,6 +130,9 @@ func (bot *CQBot) SendGroupMessage(groupId int64, m *message.SendingMessage) int
|
|||||||
}
|
}
|
||||||
m.Elements = newElem
|
m.Elements = newElem
|
||||||
ret := bot.Client.SendGroupMessage(groupId, m)
|
ret := bot.Client.SendGroupMessage(groupId, m)
|
||||||
|
if ret == nil || ret.Id == -1 {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
return bot.InsertGroupMessage(ret)
|
return bot.InsertGroupMessage(ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package coolq
|
package coolq
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/md5"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
@ -261,10 +262,23 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message.
|
|||||||
case "image":
|
case "image":
|
||||||
f := d["file"]
|
f := d["file"]
|
||||||
if strings.HasPrefix(f, "http") || strings.HasPrefix(f, "https") {
|
if strings.HasPrefix(f, "http") || strings.HasPrefix(f, "https") {
|
||||||
|
cache := d["cache"]
|
||||||
|
if cache == "" {
|
||||||
|
cache = "1"
|
||||||
|
}
|
||||||
|
hash := md5.Sum([]byte(f))
|
||||||
|
cacheFile := path.Join(global.CACHE_PATH, hex.EncodeToString(hash[:])+".cache")
|
||||||
|
if global.PathExists(cacheFile) && cache == "1" {
|
||||||
|
b, err := ioutil.ReadFile(cacheFile)
|
||||||
|
if err == nil {
|
||||||
|
return message.NewImage(b), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
b, err := global.GetBytes(f)
|
b, err := global.GetBytes(f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
_ = ioutil.WriteFile(cacheFile, b, 0644)
|
||||||
return message.NewImage(b), nil
|
return message.NewImage(b), nil
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(f, "base64") {
|
if strings.HasPrefix(f, "base64") {
|
||||||
@ -385,7 +399,7 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message.
|
|||||||
}
|
}
|
||||||
data = b
|
data = b
|
||||||
}
|
}
|
||||||
if !global.IsAMR(data) {
|
if !global.IsAMRorSILK(data) {
|
||||||
return nil, errors.New("unsupported voice file format (please use AMR file for now)")
|
return nil, errors.New("unsupported voice file format (please use AMR file for now)")
|
||||||
}
|
}
|
||||||
return &message.VoiceElement{Data: data}, nil
|
return &message.VoiceElement{Data: data}, nil
|
||||||
|
23
global/fs.go
23
global/fs.go
@ -1,17 +1,23 @@
|
|||||||
package global
|
package global
|
||||||
|
|
||||||
import (
|
import (
|
||||||
log "github.com/sirupsen/logrus"
|
"bytes"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
var IMAGE_PATH = path.Join("data", "images")
|
var (
|
||||||
|
IMAGE_PATH = path.Join("data", "images")
|
||||||
|
VOICE_PATH = path.Join("data", "voices")
|
||||||
|
VIDEO_PATH = path.Join("data", "videos")
|
||||||
|
CACHE_PATH = path.Join("data", "cache")
|
||||||
|
|
||||||
var VOICE_PATH = path.Join("data", "voices")
|
HEADER_AMR = []byte("#!AMR")
|
||||||
|
HEADER_SILK = []byte("\x02#!SILK_V3")
|
||||||
var VIDEO_PATH = path.Join("data", "videos")
|
)
|
||||||
|
|
||||||
func PathExists(path string) bool {
|
func PathExists(path string) bool {
|
||||||
_, err := os.Stat(path)
|
_, err := os.Stat(path)
|
||||||
@ -36,9 +42,6 @@ func Check(err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsAMR(b []byte) bool {
|
func IsAMRorSILK(b []byte) bool {
|
||||||
if len(b) <= 6 {
|
return bytes.HasPrefix(b, HEADER_AMR) || bytes.HasPrefix(b, HEADER_SILK)
|
||||||
return false
|
|
||||||
}
|
|
||||||
return b[0] == 0x23 && b[1] == 0x21 && b[2] == 0x41 && b[3] == 0x4D && b[4] == 0x52 // amr file header
|
|
||||||
}
|
}
|
||||||
|
50
global/param.go
Normal file
50
global/param.go
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
package global
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/tidwall/gjson"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
var trueSet = map[string]struct{}{
|
||||||
|
"true": {},
|
||||||
|
"yes": {},
|
||||||
|
"1": {},
|
||||||
|
}
|
||||||
|
|
||||||
|
var falseSet = map[string]struct{}{
|
||||||
|
"false": {},
|
||||||
|
"no": {},
|
||||||
|
"0": {},
|
||||||
|
}
|
||||||
|
|
||||||
|
func EnsureBool(p interface{}, defaultVal bool) bool {
|
||||||
|
var str string
|
||||||
|
if b, ok := p.(bool); ok {
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
if j, ok := p.(gjson.Result); ok {
|
||||||
|
if !j.Exists() {
|
||||||
|
return defaultVal
|
||||||
|
}
|
||||||
|
if j.Type == gjson.True {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if j.Type == gjson.False {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if j.Type != gjson.String {
|
||||||
|
return defaultVal
|
||||||
|
}
|
||||||
|
str = j.Str
|
||||||
|
} else if s, ok := p.(string); ok {
|
||||||
|
str = s
|
||||||
|
}
|
||||||
|
str = strings.ToLower(str)
|
||||||
|
if _, ok := trueSet[str]; ok {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if _, ok := falseSet[str]; ok {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return defaultVal
|
||||||
|
}
|
2
go.mod
2
go.mod
@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp
|
|||||||
go 1.14
|
go 1.14
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20200816111850-988a766ae224
|
github.com/Mrs4s/MiraiGo v0.0.0-20200819185537-8d1e5fb04c17
|
||||||
github.com/gin-gonic/gin v1.6.3
|
github.com/gin-gonic/gin v1.6.3
|
||||||
github.com/gorilla/websocket v1.4.2
|
github.com/gorilla/websocket v1.4.2
|
||||||
github.com/guonaihong/gout v0.1.1
|
github.com/guonaihong/gout v0.1.1
|
||||||
|
6
go.sum
6
go.sum
@ -1,9 +1,7 @@
|
|||||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20200813091456-988a010b51df h1:ERLrnv7bONrg4NqvC8AWhtEgCZk97uCZdRpQS4gF8UE=
|
github.com/Mrs4s/MiraiGo v0.0.0-20200819185537-8d1e5fb04c17 h1:sY4lwW34serGKnD26hP7ZLpnJ4NfVYKdS2SJIW1Mezs=
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20200813091456-988a010b51df/go.mod h1:0je03wji/tSw4bUH4QCF2Z4/EjyNWjSJTyy5tliX6EM=
|
github.com/Mrs4s/MiraiGo v0.0.0-20200819185537-8d1e5fb04c17/go.mod h1:0je03wji/tSw4bUH4QCF2Z4/EjyNWjSJTyy5tliX6EM=
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20200816111850-988a766ae224 h1:tlWc7RpBCh5VhT0H6wzm/knxj2PpAV3J7wQyieF0nkk=
|
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20200816111850-988a766ae224/go.mod h1:0je03wji/tSw4bUH4QCF2Z4/EjyNWjSJTyy5tliX6EM=
|
|
||||||
github.com/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0=
|
github.com/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0=
|
||||||
github.com/bwmarrin/snowflake v0.3.0/go.mod h1:NdZxfVWX+oR6y2K0o6qAYv6gIOP9rjG0/E9WsDpxqwE=
|
github.com/bwmarrin/snowflake v0.3.0/go.mod h1:NdZxfVWX+oR6y2K0o6qAYv6gIOP9rjG0/E9WsDpxqwE=
|
||||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||||
|
5
main.go
5
main.go
@ -51,6 +51,11 @@ func init() {
|
|||||||
log.Fatalf("创建视频缓存文件夹失败: %v", err)
|
log.Fatalf("创建视频缓存文件夹失败: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if !global.PathExists(global.CACHE_PATH) {
|
||||||
|
if err := os.MkdirAll(global.CACHE_PATH, 0755); err != nil {
|
||||||
|
log.Fatalf("创建发送图片缓存文件夹失败: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
if global.PathExists("cqhttp.json") {
|
if global.PathExists("cqhttp.json") {
|
||||||
log.Info("发现 cqhttp.json 将在五秒后尝试导入配置,按 Ctrl+C 取消.")
|
log.Info("发现 cqhttp.json 将在五秒后尝试导入配置,按 Ctrl+C 取消.")
|
||||||
log.Warn("警告: 该操作会删除 cqhttp.json 并覆盖 config.json 文件.")
|
log.Warn("警告: 该操作会删除 cqhttp.json 并覆盖 config.json 文件.")
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Mrs4s/go-cqhttp/coolq"
|
"github.com/Mrs4s/go-cqhttp/coolq"
|
||||||
|
"github.com/Mrs4s/go-cqhttp/global"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/guonaihong/gout"
|
"github.com/guonaihong/gout"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
@ -133,12 +134,12 @@ func (s *httpServer) Run(addr, authToken string, bot *coolq.CQBot) {
|
|||||||
s.engine.Any("/set_group_leave_async", s.SetGroupLeave)
|
s.engine.Any("/set_group_leave_async", s.SetGroupLeave)
|
||||||
|
|
||||||
s.engine.Any("/get_image", s.GetImage)
|
s.engine.Any("/get_image", s.GetImage)
|
||||||
s.engine.Any("/get_image_async", s.GetImage)
|
|
||||||
|
|
||||||
s.engine.Any("/get_forward_msg", s.GetForwardMessage)
|
s.engine.Any("/get_forward_msg", s.GetForwardMessage)
|
||||||
|
|
||||||
s.engine.Any("/get_group_msg", s.GetGroupMessage)
|
s.engine.Any("/get_group_msg", s.GetGroupMessage)
|
||||||
s.engine.Any("/get_group_msg_async", s.GetGroupMessage)
|
|
||||||
|
s.engine.Any("/get_group_honor_info", s.GetGroupHonorInfo)
|
||||||
|
|
||||||
s.engine.Any("/can_send_image", s.CanSendImage)
|
s.engine.Any("/can_send_image", s.CanSendImage)
|
||||||
s.engine.Any("/can_send_image_async", s.CanSendImage)
|
s.engine.Any("/can_send_image_async", s.CanSendImage)
|
||||||
@ -208,7 +209,8 @@ func (s *httpServer) GetFriendList(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) GetGroupList(c *gin.Context) {
|
func (s *httpServer) GetGroupList(c *gin.Context) {
|
||||||
c.JSON(200, s.bot.CQGetGroupList())
|
nc := getParamOrDefault(c, "no_cache", "false")
|
||||||
|
c.JSON(200, s.bot.CQGetGroupList(nc == "true"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) GetGroupInfo(c *gin.Context) {
|
func (s *httpServer) GetGroupInfo(c *gin.Context) {
|
||||||
@ -249,21 +251,23 @@ func (s *httpServer) SendMessage(c *gin.Context) {
|
|||||||
func (s *httpServer) SendPrivateMessage(c *gin.Context) {
|
func (s *httpServer) SendPrivateMessage(c *gin.Context) {
|
||||||
uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64)
|
uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64)
|
||||||
msg, t := getParamWithType(c, "message")
|
msg, t := getParamWithType(c, "message")
|
||||||
|
autoEscape := global.EnsureBool(getParam(c, "auto_escape"), false)
|
||||||
if t == gjson.JSON {
|
if t == gjson.JSON {
|
||||||
c.JSON(200, s.bot.CQSendPrivateMessage(uid, gjson.Parse(msg)))
|
c.JSON(200, s.bot.CQSendPrivateMessage(uid, gjson.Parse(msg), autoEscape))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.JSON(200, s.bot.CQSendPrivateMessage(uid, msg))
|
c.JSON(200, s.bot.CQSendPrivateMessage(uid, msg, autoEscape))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) SendGroupMessage(c *gin.Context) {
|
func (s *httpServer) SendGroupMessage(c *gin.Context) {
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
||||||
msg, t := getParamWithType(c, "message")
|
msg, t := getParamWithType(c, "message")
|
||||||
|
autoEscape := global.EnsureBool(getParam(c, "auto_escape"), false)
|
||||||
if t == gjson.JSON {
|
if t == gjson.JSON {
|
||||||
c.JSON(200, s.bot.CQSendGroupMessage(gid, gjson.Parse(msg)))
|
c.JSON(200, s.bot.CQSendGroupMessage(gid, gjson.Parse(msg), autoEscape))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.JSON(200, s.bot.CQSendGroupMessage(gid, msg))
|
c.JSON(200, s.bot.CQSendGroupMessage(gid, msg, autoEscape))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) SendGroupForwardMessage(c *gin.Context) {
|
func (s *httpServer) SendGroupForwardMessage(c *gin.Context) {
|
||||||
@ -282,6 +286,11 @@ func (s *httpServer) GetGroupMessage(c *gin.Context) {
|
|||||||
c.JSON(200, s.bot.CQGetGroupMessage(int32(mid)))
|
c.JSON(200, s.bot.CQGetGroupMessage(int32(mid)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *httpServer) GetGroupHonorInfo(c *gin.Context) {
|
||||||
|
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
||||||
|
c.JSON(200, s.bot.CQGetGroupHonorInfo(gid, getParam(c, "type")))
|
||||||
|
}
|
||||||
|
|
||||||
func (s *httpServer) ProcessFriendRequest(c *gin.Context) {
|
func (s *httpServer) ProcessFriendRequest(c *gin.Context) {
|
||||||
flag := getParam(c, "flag")
|
flag := getParam(c, "flag")
|
||||||
approve := getParamOrDefault(c, "approve", "true")
|
approve := getParamOrDefault(c, "approve", "true")
|
||||||
|
@ -7,7 +7,6 @@ import (
|
|||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
wsc "golang.org/x/net/websocket"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -29,8 +28,8 @@ type websocketClient struct {
|
|||||||
bot *coolq.CQBot
|
bot *coolq.CQBot
|
||||||
|
|
||||||
pushLock *sync.Mutex
|
pushLock *sync.Mutex
|
||||||
universalConn *wsc.Conn
|
universalConn *websocket.Conn
|
||||||
eventConn *wsc.Conn
|
eventConn *websocket.Conn
|
||||||
}
|
}
|
||||||
|
|
||||||
var WebsocketServer = &websocketServer{}
|
var WebsocketServer = &websocketServer{}
|
||||||
@ -79,18 +78,15 @@ func (c *websocketClient) Run() {
|
|||||||
|
|
||||||
func (c *websocketClient) connectApi() {
|
func (c *websocketClient) connectApi() {
|
||||||
log.Infof("开始尝试连接到反向Websocket API服务器: %v", c.conf.ReverseApiUrl)
|
log.Infof("开始尝试连接到反向Websocket API服务器: %v", c.conf.ReverseApiUrl)
|
||||||
wsConf, err := wsc.NewConfig(c.conf.ReverseApiUrl, c.conf.ReverseApiUrl)
|
header := http.Header{
|
||||||
if err != nil {
|
"X-Client-Role": []string{"API"},
|
||||||
log.Warnf("连接到反向Websocket API服务器 %v 时出现致命错误: %v", c.conf.ReverseApiUrl, err)
|
"X-Self-ID": []string{strconv.FormatInt(c.bot.Client.Uin, 10)},
|
||||||
return
|
"User-Agent": []string{"CQHttp/4.15.0"},
|
||||||
}
|
}
|
||||||
wsConf.Header["X-Client-Role"] = []string{"API"}
|
|
||||||
wsConf.Header["X-Self-ID"] = []string{strconv.FormatInt(c.bot.Client.Uin, 10)}
|
|
||||||
wsConf.Header["User-Agent"] = []string{"CQHttp/4.15.0"}
|
|
||||||
if c.token != "" {
|
if c.token != "" {
|
||||||
wsConf.Header["Authorization"] = []string{"Token " + c.token}
|
header["Authorization"] = []string{"Token " + c.token}
|
||||||
}
|
}
|
||||||
conn, err := wsc.DialConfig(wsConf)
|
conn, _, err := websocket.DefaultDialer.Dial(c.conf.ReverseApiUrl, header)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("连接到反向Websocket API服务器 %v 时出现错误: %v", c.conf.ReverseApiUrl, err)
|
log.Warnf("连接到反向Websocket API服务器 %v 时出现错误: %v", c.conf.ReverseApiUrl, err)
|
||||||
if c.conf.ReverseReconnectInterval != 0 {
|
if c.conf.ReverseReconnectInterval != 0 {
|
||||||
@ -105,23 +101,20 @@ func (c *websocketClient) connectApi() {
|
|||||||
|
|
||||||
func (c *websocketClient) connectEvent() {
|
func (c *websocketClient) connectEvent() {
|
||||||
log.Infof("开始尝试连接到反向Websocket Event服务器: %v", c.conf.ReverseEventUrl)
|
log.Infof("开始尝试连接到反向Websocket Event服务器: %v", c.conf.ReverseEventUrl)
|
||||||
wsConf, err := wsc.NewConfig(c.conf.ReverseEventUrl, c.conf.ReverseEventUrl)
|
header := http.Header{
|
||||||
if err != nil {
|
"X-Client-Role": []string{"Event"},
|
||||||
log.Warnf("连接到反向Websocket Event服务器 %v 时出现致命错误: %v", c.conf.ReverseApiUrl, err)
|
"X-Self-ID": []string{strconv.FormatInt(c.bot.Client.Uin, 10)},
|
||||||
return
|
"User-Agent": []string{"CQHttp/4.15.0"},
|
||||||
}
|
}
|
||||||
wsConf.Header["X-Client-Role"] = []string{"Event"}
|
|
||||||
wsConf.Header["X-Self-ID"] = []string{strconv.FormatInt(c.bot.Client.Uin, 10)}
|
|
||||||
wsConf.Header["User-Agent"] = []string{"CQHttp/4.15.0"}
|
|
||||||
if c.token != "" {
|
if c.token != "" {
|
||||||
wsConf.Header["Authorization"] = []string{"Token " + c.token}
|
header["Authorization"] = []string{"Token " + c.token}
|
||||||
}
|
}
|
||||||
conn, err := wsc.DialConfig(wsConf)
|
conn, _, err := websocket.DefaultDialer.Dial(c.conf.ReverseEventUrl, header)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("连接到反向Websocket API服务器 %v 时出现错误: %v", c.conf.ReverseApiUrl, err)
|
log.Warnf("连接到反向Websocket Event服务器 %v 时出现错误: %v", c.conf.ReverseEventUrl, err)
|
||||||
if c.conf.ReverseReconnectInterval != 0 {
|
if c.conf.ReverseReconnectInterval != 0 {
|
||||||
time.Sleep(time.Millisecond * time.Duration(c.conf.ReverseReconnectInterval))
|
time.Sleep(time.Millisecond * time.Duration(c.conf.ReverseReconnectInterval))
|
||||||
c.connectApi()
|
c.connectEvent()
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -131,18 +124,15 @@ func (c *websocketClient) connectEvent() {
|
|||||||
|
|
||||||
func (c *websocketClient) connectUniversal() {
|
func (c *websocketClient) connectUniversal() {
|
||||||
log.Infof("开始尝试连接到反向Websocket Universal服务器: %v", c.conf.ReverseUrl)
|
log.Infof("开始尝试连接到反向Websocket Universal服务器: %v", c.conf.ReverseUrl)
|
||||||
wsConf, err := wsc.NewConfig(c.conf.ReverseUrl, c.conf.ReverseUrl)
|
header := http.Header{
|
||||||
if err != nil {
|
"X-Client-Role": []string{"Universal"},
|
||||||
log.Warnf("连接到反向Websocket Universal服务器 %v 时出现致命错误: %v", c.conf.ReverseUrl, err)
|
"X-Self-ID": []string{strconv.FormatInt(c.bot.Client.Uin, 10)},
|
||||||
return
|
"User-Agent": []string{"CQHttp/4.15.0"},
|
||||||
}
|
}
|
||||||
wsConf.Header["X-Client-Role"] = []string{"Universal"}
|
|
||||||
wsConf.Header["X-Self-ID"] = []string{strconv.FormatInt(c.bot.Client.Uin, 10)}
|
|
||||||
wsConf.Header["User-Agent"] = []string{"CQHttp/4.15.0"}
|
|
||||||
if c.token != "" {
|
if c.token != "" {
|
||||||
wsConf.Header["Authorization"] = []string{"Token " + c.token}
|
header["Authorization"] = []string{"Token " + c.token}
|
||||||
}
|
}
|
||||||
conn, err := wsc.DialConfig(wsConf)
|
conn, _, err := websocket.DefaultDialer.Dial(c.conf.ReverseUrl, header)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("连接到反向Websocket Universal服务器 %v 时出现错误: %v", c.conf.ReverseUrl, err)
|
log.Warnf("连接到反向Websocket Universal服务器 %v 时出现错误: %v", c.conf.ReverseUrl, err)
|
||||||
if c.conf.ReverseReconnectInterval != 0 {
|
if c.conf.ReverseReconnectInterval != 0 {
|
||||||
@ -155,12 +145,12 @@ func (c *websocketClient) connectUniversal() {
|
|||||||
c.universalConn = conn
|
c.universalConn = conn
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *websocketClient) listenApi(conn *wsc.Conn, u bool) {
|
func (c *websocketClient) listenApi(conn *websocket.Conn, u bool) {
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
for {
|
for {
|
||||||
var buf []byte
|
_, buf, err := conn.ReadMessage()
|
||||||
err := wsc.Message.Receive(conn, &buf)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Warnf("监听反向WS API时出现错误: %v", err)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
j := gjson.ParseBytes(buf)
|
j := gjson.ParseBytes(buf)
|
||||||
@ -173,7 +163,7 @@ func (c *websocketClient) listenApi(conn *wsc.Conn, u bool) {
|
|||||||
}
|
}
|
||||||
c.pushLock.Lock()
|
c.pushLock.Lock()
|
||||||
log.Debugf("准备发送API %v 处理结果: %v", t, ret.ToJson())
|
log.Debugf("准备发送API %v 处理结果: %v", t, ret.ToJson())
|
||||||
_, _ = conn.Write([]byte(ret.ToJson()))
|
_ = conn.WriteJSON(ret)
|
||||||
c.pushLock.Unlock()
|
c.pushLock.Unlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -190,7 +180,8 @@ func (c *websocketClient) onBotPushEvent(m coolq.MSG) {
|
|||||||
defer c.pushLock.Unlock()
|
defer c.pushLock.Unlock()
|
||||||
if c.eventConn != nil {
|
if c.eventConn != nil {
|
||||||
log.Debugf("向WS服务器 %v 推送Event: %v", c.eventConn.RemoteAddr().String(), m.ToJson())
|
log.Debugf("向WS服务器 %v 推送Event: %v", c.eventConn.RemoteAddr().String(), m.ToJson())
|
||||||
if _, err := c.eventConn.Write([]byte(m.ToJson())); err != nil {
|
if err := c.eventConn.WriteJSON(m); err != nil {
|
||||||
|
log.Warnf("向WS服务器 %v 推送Event时出现错误: %v", c.eventConn.RemoteAddr().String(), err)
|
||||||
_ = c.eventConn.Close()
|
_ = c.eventConn.Close()
|
||||||
if c.conf.ReverseReconnectInterval != 0 {
|
if c.conf.ReverseReconnectInterval != 0 {
|
||||||
go func() {
|
go func() {
|
||||||
@ -202,7 +193,8 @@ func (c *websocketClient) onBotPushEvent(m coolq.MSG) {
|
|||||||
}
|
}
|
||||||
if c.universalConn != nil {
|
if c.universalConn != nil {
|
||||||
log.Debugf("向WS服务器 %v 推送Event: %v", c.universalConn.RemoteAddr().String(), m.ToJson())
|
log.Debugf("向WS服务器 %v 推送Event: %v", c.universalConn.RemoteAddr().String(), m.ToJson())
|
||||||
if _, err := c.universalConn.Write([]byte(m.ToJson())); err != nil {
|
if err := c.universalConn.WriteJSON(m); err != nil {
|
||||||
|
log.Warnf("向WS服务器 %v 推送Event时出现错误: %v", c.universalConn.RemoteAddr().String(), err)
|
||||||
_ = c.universalConn.Close()
|
_ = c.universalConn.Close()
|
||||||
if c.conf.ReverseReconnectInterval != 0 {
|
if c.conf.ReverseReconnectInterval != 0 {
|
||||||
go func() {
|
go func() {
|
||||||
@ -322,7 +314,7 @@ var wsApi = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{
|
|||||||
return bot.CQGetFriendList()
|
return bot.CQGetFriendList()
|
||||||
},
|
},
|
||||||
"get_group_list": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
"get_group_list": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
return bot.CQGetGroupList()
|
return bot.CQGetGroupList(p.Get("no_cache").Bool())
|
||||||
},
|
},
|
||||||
"get_group_info": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
"get_group_info": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
return bot.CQGetGroupInfo(p.Get("group_id").Int())
|
return bot.CQGetGroupInfo(p.Get("group_id").Int())
|
||||||
@ -337,28 +329,29 @@ var wsApi = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
"send_msg": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
"send_msg": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
|
autoEscape := global.EnsureBool(p.Get("auto_escape"), false)
|
||||||
if p.Get("message_type").Str == "private" {
|
if p.Get("message_type").Str == "private" {
|
||||||
return bot.CQSendPrivateMessage(p.Get("user_id").Int(), p.Get("message"))
|
return bot.CQSendPrivateMessage(p.Get("user_id").Int(), p.Get("message"), autoEscape)
|
||||||
}
|
}
|
||||||
if p.Get("message_type").Str == "group" {
|
if p.Get("message_type").Str == "group" {
|
||||||
return bot.CQSendGroupMessage(p.Get("group_id").Int(), p.Get("message"))
|
return bot.CQSendGroupMessage(p.Get("group_id").Int(), p.Get("message"), autoEscape)
|
||||||
}
|
}
|
||||||
if p.Get("group_id").Int() != 0 {
|
if p.Get("group_id").Int() != 0 {
|
||||||
return bot.CQSendGroupMessage(p.Get("group_id").Int(), p.Get("message"))
|
return bot.CQSendGroupMessage(p.Get("group_id").Int(), p.Get("message"), autoEscape)
|
||||||
}
|
}
|
||||||
if p.Get("user_id").Int() != 0 {
|
if p.Get("user_id").Int() != 0 {
|
||||||
return bot.CQSendPrivateMessage(p.Get("user_id").Int(), p.Get("message"))
|
return bot.CQSendPrivateMessage(p.Get("user_id").Int(), p.Get("message"), autoEscape)
|
||||||
}
|
}
|
||||||
return coolq.MSG{}
|
return coolq.MSG{}
|
||||||
},
|
},
|
||||||
"send_group_msg": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
"send_group_msg": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
return bot.CQSendGroupMessage(p.Get("group_id").Int(), p.Get("message"))
|
return bot.CQSendGroupMessage(p.Get("group_id").Int(), p.Get("message"), global.EnsureBool(p.Get("auto_escape"), false))
|
||||||
},
|
},
|
||||||
"send_group_forward_msg": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
"send_group_forward_msg": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
return bot.CQSendGroupForwardMessage(p.Get("group_id").Int(), p.Get("messages"))
|
return bot.CQSendGroupForwardMessage(p.Get("group_id").Int(), p.Get("messages"))
|
||||||
},
|
},
|
||||||
"send_private_msg": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
"send_private_msg": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
return bot.CQSendPrivateMessage(p.Get("user_id").Int(), p.Get("message"))
|
return bot.CQSendPrivateMessage(p.Get("user_id").Int(), p.Get("message"), global.EnsureBool(p.Get("auto_escape"), false))
|
||||||
},
|
},
|
||||||
"delete_msg": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
"delete_msg": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
return bot.CQDeleteMessage(int32(p.Get("message_id").Int()))
|
return bot.CQDeleteMessage(int32(p.Get("message_id").Int()))
|
||||||
@ -421,6 +414,9 @@ var wsApi = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{
|
|||||||
"get_group_msg": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
"get_group_msg": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
return bot.CQGetGroupMessage(int32(p.Get("message_id").Int()))
|
return bot.CQGetGroupMessage(int32(p.Get("message_id").Int()))
|
||||||
},
|
},
|
||||||
|
"get_group_honor_info": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
|
return bot.CQGetGroupHonorInfo(p.Get("group_id").Int(), p.Get("type").Str)
|
||||||
|
},
|
||||||
"can_send_image": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
"can_send_image": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
return bot.CQCanSendImage()
|
return bot.CQCanSendImage()
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user