1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-05 03:23:49 +08:00

feature support .get_word_slices

This commit is contained in:
wdvxdr 2020-10-02 23:41:02 +08:00
parent 9cd044c402
commit bbf2025350
6 changed files with 39 additions and 4 deletions

View File

@ -102,6 +102,17 @@ func (bot *CQBot) CQGetGroupMemberInfo(groupId, userId int64) MSG {
return OK(convertGroupMemberInfo(groupId, member)) return OK(convertGroupMemberInfo(groupId, member))
} }
func (bot *CQBot) CQGetWordSlices(content string) MSG {
slices, err := bot.Client.GetWordSegmentation(content)
if err != nil {
return Failed(100)
}
for i := 0; i < len(slices); i++ {
slices[i] = strings.ReplaceAll(slices[i], "\u0000", "")
}
return OK(MSG{"slices": slices})
}
// 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{}, autoEscape bool) MSG { func (bot *CQBot) CQSendGroupMessage(groupId int64, i interface{}, autoEscape bool) MSG {
var str string var str string

View File

@ -361,9 +361,9 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message.
t, _ := strconv.ParseInt(d["qq"], 10, 64) t, _ := strconv.ParseInt(d["qq"], 10, 64)
id, _ := strconv.Atoi(d["id"]) id, _ := strconv.Atoi(d["id"])
if id < 0 || id >= 9 { if id < 0 || id >= 9 {
return nil,errors.New("invalid gift id") return nil, errors.New("invalid gift id")
} }
return &GiftElement{Target: t,GiftId: GiftId[id]}, nil return &GiftElement{Target: t, GiftId: GiftId[id]}, nil
case "record": case "record":
if !group { if !group {
return nil, errors.New("private voice unsupported now") return nil, errors.New("private voice unsupported now")

View File

@ -418,7 +418,21 @@ Type: `cardimage`
| `group_id` | int64 | 群号 | | `group_id` | int64 | 群号 |
| `messages` | forward node[] | 自定义转发消息, 具体看CQCode | | `messages` | forward node[] | 自定义转发消息, 具体看CQCode |
### ### 获取中文分词
终结点: `/.get_word_slices`
**参数**
| 字段 | 类型 | 说明 |
| ------------ | ------ | ------ |
| `content` | string | 内容 |
**响应数据**
| 字段 | 类型 | 说明 |
| ---------- | ----------------- | -------- |
| `slices` | string[] | 词组 |
## 事件 ## 事件

View File

@ -50,4 +50,3 @@ func NeteaseMusicSongInfo(id string) (gjson.Result, error) {
} }
return gjson.ParseBytes(d).Get("songs.0"), nil return gjson.ParseBytes(d).Get("songs.0"), nil
} }

View File

@ -354,6 +354,11 @@ func (s *httpServer) OcrImage(c *gin.Context) {
c.JSON(200, s.bot.CQOcrImage(img)) c.JSON(200, s.bot.CQOcrImage(img))
} }
func (s *httpServer) GetWordSlices(c *gin.Context) {
content := getParam(c, "content")
c.JSON(200, s.bot.CQGetWordSlices(content))
}
func (s *httpServer) SetGroupPortrait(c *gin.Context) { func (s *httpServer) SetGroupPortrait(c *gin.Context) {
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64) gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
file := getParam(c, "file") file := getParam(c, "file")
@ -518,4 +523,7 @@ var httpApi = map[string]func(s *httpServer, c *gin.Context){
".ocr_image": func(s *httpServer, c *gin.Context) { ".ocr_image": func(s *httpServer, c *gin.Context) {
s.OcrImage(c) s.OcrImage(c)
}, },
".get_word_slices": func(s *httpServer, c *gin.Context) {
s.GetWordSlices(c)
},
} }

View File

@ -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)
}, },
".get_word_slices": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
return bot.CQGetWordSlices(p.Get("content").Str)
},
"set_group_portrait": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG { "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()) return bot.CQSetGroupPortrait(p.Get("group_id").Int(), p.Get("file").String(), p.Get("cache").String())
}, },