mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-05 11:33:48 +08:00
feature set_group_portrait
[2020-09-22 10:50:46] [ERROR]: 读取服务器地址时出现错误: %vEOF
This commit is contained in:
parent
995737b0b8
commit
d2d408a8e9
13
coolq/api.go
13
coolq/api.go
@ -667,6 +667,19 @@ func (bot *CQBot) CQReloadEventFilter() MSG {
|
|||||||
return OK(nil)
|
return OK(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (bot *CQBot) CQSetGroupPortrait(groupId int64, file, cache string) MSG {
|
||||||
|
if g := bot.Client.FindGroup(groupId); g != nil {
|
||||||
|
img, err := global.FindFile(file, cache, global.IMAGE_PATH)
|
||||||
|
if err != nil {
|
||||||
|
log.Warnf("set group portrait error: %v", err)
|
||||||
|
return Failed(100)
|
||||||
|
}
|
||||||
|
g.UpdateGroupHeadPortrait(img)
|
||||||
|
return OK(nil)
|
||||||
|
}
|
||||||
|
return Failed(100)
|
||||||
|
}
|
||||||
|
|
||||||
func (bot *CQBot) CQGetStatus() MSG {
|
func (bot *CQBot) CQGetStatus() MSG {
|
||||||
return OK(MSG{
|
return OK(MSG{
|
||||||
"app_initialized": true,
|
"app_initialized": true,
|
||||||
|
52
global/fs.go
52
global/fs.go
@ -2,11 +2,17 @@ package global
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"crypto/md5"
|
||||||
|
"encoding/base64"
|
||||||
|
"encoding/hex"
|
||||||
|
"errors"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"runtime"
|
||||||
log "github.com/sirupsen/logrus"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -45,3 +51,45 @@ func Check(err error) {
|
|||||||
func IsAMRorSILK(b []byte) bool {
|
func IsAMRorSILK(b []byte) bool {
|
||||||
return bytes.HasPrefix(b, HEADER_AMR) || bytes.HasPrefix(b, HEADER_SILK)
|
return bytes.HasPrefix(b, HEADER_AMR) || bytes.HasPrefix(b, HEADER_SILK)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FindFile(f, cache, PATH string) (data []byte, err error) {
|
||||||
|
data, err = nil, errors.New("can't find the file: "+f)
|
||||||
|
if strings.HasPrefix(f, "http") || strings.HasPrefix(f, "https") {
|
||||||
|
if cache == "" {
|
||||||
|
cache = "1"
|
||||||
|
}
|
||||||
|
hash := md5.Sum([]byte(f))
|
||||||
|
cacheFile := path.Join(CACHE_PATH, hex.EncodeToString(hash[:])+".cache")
|
||||||
|
if PathExists(cacheFile) && cache == "1" {
|
||||||
|
return ioutil.ReadFile(cacheFile)
|
||||||
|
}
|
||||||
|
data, err = GetBytes(f)
|
||||||
|
_ = ioutil.WriteFile(cacheFile, data, 0644)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
} else if strings.HasPrefix(f, "base64") {
|
||||||
|
data, err = base64.StdEncoding.DecodeString(strings.ReplaceAll(f, "base64://", ""))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
} else if strings.HasPrefix(f, "file") {
|
||||||
|
fu, err := url.Parse(f)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if strings.HasPrefix(fu.Path, "/") && runtime.GOOS == `windows` {
|
||||||
|
fu.Path = fu.Path[1:]
|
||||||
|
}
|
||||||
|
data, err = ioutil.ReadFile(fu.Path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
} else if PathExists(path.Join(PATH, f)) {
|
||||||
|
data, err = ioutil.ReadFile(path.Join(PATH, f))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
2
go.mod
2
go.mod
@ -25,7 +25,7 @@ require (
|
|||||||
github.com/xujiajun/nutsdb v0.5.0
|
github.com/xujiajun/nutsdb v0.5.0
|
||||||
github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189
|
github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189
|
||||||
golang.org/x/net v0.0.0-20200904194848-62affa334b73 // indirect
|
golang.org/x/net v0.0.0-20200904194848-62affa334b73 // indirect
|
||||||
golang.org/x/sys v0.0.0-20200909081042-eff7692f9009 // indirect
|
golang.org/x/sys v0.0.0-20200916084744-dbad9cb7cb7a // indirect
|
||||||
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e
|
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e
|
||||||
gopkg.in/yaml.v2 v2.3.0 // indirect
|
gopkg.in/yaml.v2 v2.3.0 // indirect
|
||||||
)
|
)
|
||||||
|
2
main.go
2
main.go
@ -260,7 +260,7 @@ func main() {
|
|||||||
func() {
|
func() {
|
||||||
defer func() {
|
defer func() {
|
||||||
if pan := recover(); pan != nil {
|
if pan := recover(); pan != nil {
|
||||||
log.Error("读取服务器地址时出现错误: %v", pan)
|
log.Error("读取服务器地址时出现错误: ", pan)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
r := binary.NewReader(data)
|
r := binary.NewReader(data)
|
||||||
|
@ -354,6 +354,13 @@ func (s *httpServer) OcrImage(c *gin.Context) {
|
|||||||
c.JSON(200, s.bot.CQOcrImage(img))
|
c.JSON(200, s.bot.CQOcrImage(img))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *httpServer) SetGroupPortrait(c *gin.Context) {
|
||||||
|
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
||||||
|
file := getParam(c, "file")
|
||||||
|
cache := getParam(c, "cache")
|
||||||
|
c.JSON(200, s.bot.CQSetGroupPortrait(gid, file, cache))
|
||||||
|
}
|
||||||
|
|
||||||
func getParamOrDefault(c *gin.Context, k, def string) string {
|
func getParamOrDefault(c *gin.Context, k, def string) string {
|
||||||
r := getParam(c, k)
|
r := getParam(c, k)
|
||||||
if r != "" {
|
if r != "" {
|
||||||
@ -502,6 +509,9 @@ var httpApi = map[string]func(s *httpServer, c *gin.Context){
|
|||||||
"reload_event_filter": func(s *httpServer, c *gin.Context) {
|
"reload_event_filter": func(s *httpServer, c *gin.Context) {
|
||||||
s.ReloadEventFilter(c)
|
s.ReloadEventFilter(c)
|
||||||
},
|
},
|
||||||
|
"set_group_portrait": func(s *httpServer, c *gin.Context) {
|
||||||
|
s.SetGroupPortrait(c)
|
||||||
|
},
|
||||||
".handle_quick_operation": func(s *httpServer, c *gin.Context) {
|
".handle_quick_operation": func(s *httpServer, c *gin.Context) {
|
||||||
s.HandleQuickOperation(c)
|
s.HandleQuickOperation(c)
|
||||||
},
|
},
|
||||||
|
@ -504,6 +504,9 @@ var wsApi = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{
|
|||||||
".ocr_image": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
".ocr_image": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
return bot.CQOcrImage(p.Get("image").Str)
|
return bot.CQOcrImage(p.Get("image").Str)
|
||||||
},
|
},
|
||||||
|
"set_group_portrait": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
|
return bot.CQSetGroupPortrait(p.Get("group_id").Int(), p.Get("file").String(), p.Get("cache").String())
|
||||||
|
},
|
||||||
".handle_quick_operation": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
".handle_quick_operation": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
return bot.CQHandleQuickOperation(p.Get("context"), p.Get("operation"))
|
return bot.CQHandleQuickOperation(p.Get("context"), p.Get("operation"))
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user