mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-07 12:43:31 +08:00
Merge pull request #339 from wdvxdr1123/dev
feature support .get_word_slices
This commit is contained in:
commit
a712db5d50
11
coolq/api.go
11
coolq/api.go
@ -102,6 +102,17 @@ func (bot *CQBot) CQGetGroupMemberInfo(groupId, userId int64) MSG {
|
||||
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
|
||||
func (bot *CQBot) CQSendGroupMessage(groupId int64, i interface{}, autoEscape bool) MSG {
|
||||
var str string
|
||||
|
@ -361,9 +361,18 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message.
|
||||
t, _ := strconv.ParseInt(d["qq"], 10, 64)
|
||||
id, _ := strconv.Atoi(d["id"])
|
||||
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 "tts":
|
||||
if !group {
|
||||
return nil, errors.New("private voice unsupported now")
|
||||
}
|
||||
data, err := bot.Client.GetTts(d["text"])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &message.VoiceElement{Data: data}, nil
|
||||
case "record":
|
||||
if !group {
|
||||
return nil, errors.New("private voice unsupported now")
|
||||
|
@ -287,6 +287,22 @@ Type: `cardimage`
|
||||
[CQ:cardimage,file=https://i.pixiv.cat/img-master/img/2020/03/25/00/00/08/80334602_p0_master1200.jpg]
|
||||
```
|
||||
|
||||
### 文本转语音
|
||||
|
||||
> 注意:通过TX的TTS接口,采用的音源与登录账号的性别有关
|
||||
|
||||
Type: `tts`
|
||||
|
||||
范围: **发送(仅群聊)**
|
||||
|
||||
参数:
|
||||
|
||||
| 参数名 | 类型 | 说明 |
|
||||
| ------ | ------ | ----------- |
|
||||
| text | string | 内容 |
|
||||
|
||||
示例: `[CQ:tts,text=这是一条测试消息]`
|
||||
|
||||
## API
|
||||
|
||||
### 设置群名
|
||||
@ -418,7 +434,21 @@ Type: `cardimage`
|
||||
| `group_id` | int64 | 群号 |
|
||||
| `messages` | forward node[] | 自定义转发消息, 具体看CQCode |
|
||||
|
||||
###
|
||||
### 获取中文分词
|
||||
|
||||
终结点: `/.get_word_slices`
|
||||
|
||||
**参数**
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
| ------------ | ------ | ------ |
|
||||
| `content` | string | 内容 |
|
||||
|
||||
**响应数据**
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
| ---------- | ----------------- | -------- |
|
||||
| `slices` | string[] | 词组 |
|
||||
|
||||
## 事件
|
||||
|
||||
|
@ -50,4 +50,3 @@ func NeteaseMusicSongInfo(id string) (gjson.Result, error) {
|
||||
}
|
||||
return gjson.ParseBytes(d).Get("songs.0"), nil
|
||||
}
|
||||
|
||||
|
@ -356,6 +356,11 @@ func (s *httpServer) OcrImage(c *gin.Context) {
|
||||
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) {
|
||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
||||
file := getParam(c, "file")
|
||||
@ -520,4 +525,7 @@ var httpApi = map[string]func(s *httpServer, c *gin.Context){
|
||||
".ocr_image": func(s *httpServer, c *gin.Context) {
|
||||
s.OcrImage(c)
|
||||
},
|
||||
".get_word_slices": func(s *httpServer, c *gin.Context) {
|
||||
s.GetWordSlices(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 {
|
||||
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 {
|
||||
return bot.CQSetGroupPortrait(p.Get("group_id").Int(), p.Get("file").String(), p.Get("cache").String())
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user