Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
G
go-cqhttp
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
go-cqhttp
Commits
e8513da0
Commit
e8513da0
authored
Oct 07, 2020
by
Mrs4s
Committed by
GitHub
Oct 07, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #345 from wdvxdr1123/dev
feature support silk encoder
parents
7ae9c2d2
2a5f7849
Changes
6
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
93 additions
and
18 deletions
+93
-18
coolq/cqcode.go
coolq/cqcode.go
+5
-1
global/codec.go
global/codec.go
+44
-0
go.mod
go.mod
+6
-3
go.sum
go.sum
+32
-9
server/apiAdmin.go
server/apiAdmin.go
+1
-0
server/http.go
server/http.go
+5
-5
No files found.
coolq/cqcode.go
View file @
e8513da0
...
...
@@ -369,6 +369,7 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message.
return
nil
,
errors
.
New
(
"private voice unsupported now"
)
}
data
,
err
:=
bot
.
Client
.
GetTts
(
d
[
"text"
])
ioutil
.
WriteFile
(
"tts.silk"
,
data
,
777
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -383,7 +384,10 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message.
return
nil
,
err
}
if
!
global
.
IsAMRorSILK
(
data
)
{
return
nil
,
errors
.
New
(
"unsupported voice file format (please use AMR file for now)"
)
data
,
err
=
global
.
Encoder
(
data
)
if
err
!=
nil
{
return
nil
,
err
}
}
return
&
message
.
VoiceElement
{
Data
:
data
},
nil
case
"face"
:
...
...
global/codec.go
0 → 100644
View file @
e8513da0
package
global
import
(
"crypto/md5"
"errors"
"fmt"
log
"github.com/sirupsen/logrus"
"github.com/wdvxdr1123/go-silk/silk"
"io/ioutil"
"path"
"sync"
)
var
codec
silk
.
Encoder
var
useCodec
=
true
var
once
sync
.
Once
func
InitCodec
()
{
once
.
Do
(
func
()
{
log
.
Info
(
"正在加载silk编码器..."
)
err
:=
codec
.
Init
(
"data/cache"
,
"codec"
)
if
err
!=
nil
{
log
.
Error
(
err
)
useCodec
=
false
}
})
}
func
Encoder
(
data
[]
byte
)
([]
byte
,
error
)
{
if
useCodec
==
false
{
return
nil
,
errors
.
New
(
"no silk encoder"
)
}
h
:=
md5
.
New
()
h
.
Write
(
data
)
tempName
:=
fmt
.
Sprintf
(
"%x"
,
h
.
Sum
(
nil
))
if
silkPath
:=
path
.
Join
(
"data/cache"
,
tempName
+
".silk"
);
PathExists
(
silkPath
)
{
return
ioutil
.
ReadFile
(
silkPath
)
}
slk
,
err
:=
codec
.
EncodeToSilk
(
data
,
tempName
,
true
)
if
err
!=
nil
{
return
nil
,
err
}
return
slk
,
nil
}
go.mod
View file @
e8513da0
...
...
@@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp
go 1.14
require (
github.com/Mrs4s/MiraiGo v0.0.0-2020100
3051902-8a968656c116
github.com/Mrs4s/MiraiGo v0.0.0-2020100
5155759-f9b3c399e5e0
github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect
github.com/gin-gonic/gin v1.6.3
github.com/go-playground/validator/v10 v10.4.0 // indirect
...
...
@@ -22,10 +22,13 @@ require (
github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816
github.com/tebeka/strftime v0.1.5 // indirect
github.com/tidwall/gjson v1.6.1
github.com/ugorji/go v1.1.10 // indirect
github.com/wdvxdr1123/go-silk v0.0.0-20201006020916-0398076200ea
github.com/xujiajun/nutsdb v0.5.0
github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189
golang.org/x/net v0.0.0-20200930145003-4acb6c075d10 // indirect
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f // indirect
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0 // indirect
golang.org/x/net v0.0.0-20201002202402-0a1ea396d57c // indirect
golang.org/x/sys v0.0.0-20201005172224-997123666555 // indirect
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e
gopkg.in/yaml.v2 v2.3.0 // indirect
)
go.sum
View file @
e8513da0
This diff is collapsed.
Click to expand it.
server/apiAdmin.go
View file @
e8513da0
...
...
@@ -157,6 +157,7 @@ func (s *webServer) Dologin() {
}
log
.
Info
(
"正在加载事件过滤器."
)
global
.
BootFilter
()
global
.
InitCodec
()
coolq
.
IgnoreInvalidCQCode
=
conf
.
IgnoreInvalidCQCode
coolq
.
ForceFragmented
=
conf
.
ForceFragmented
log
.
Info
(
"资源初始化完成, 开始处理信息."
)
...
...
server/http.go
View file @
e8513da0
...
...
@@ -81,9 +81,9 @@ func (s *httpServer) Run(addr, authToken string, bot *coolq.CQBot) {
go
func
()
{
log
.
Infof
(
"CQ HTTP 服务器已启动: %v"
,
addr
)
s
.
Http
=
&
http
.
Server
{
Addr
:
addr
,
Handler
:
s
.
engine
,
s
.
Http
=
&
http
.
Server
{
Addr
:
addr
,
Handler
:
s
.
engine
,
}
if
err
:=
s
.
Http
.
ListenAndServe
();
err
!=
nil
&&
err
!=
http
.
ErrServerClosed
{
log
.
Error
(
err
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment