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
1896043d
Commit
1896043d
authored
Aug 05, 2020
by
nanahira
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of github.com:Mrs4s/go-cqhttp
parents
db7f47a5
8094553b
Pipeline
#475
failed with stages
in 5 minutes and 34 seconds
Changes
11
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
759 additions
and
45 deletions
+759
-45
.github/workflows/ci.yml
.github/workflows/ci.yml
+52
-0
.github/workflows/release.yml
.github/workflows/release.yml
+4
-0
LICENSE
LICENSE
+661
-21
coolq/api.go
coolq/api.go
+7
-5
coolq/bot.go
coolq/bot.go
+11
-9
coolq/cqcode.go
coolq/cqcode.go
+16
-0
coolq/event.go
coolq/event.go
+1
-0
global/config.go
global/config.go
+1
-1
go.mod
go.mod
+1
-2
go.sum
go.sum
+2
-4
server/websocket.go
server/websocket.go
+3
-3
No files found.
.github/workflows/ci.yml
0 → 100644
View file @
1896043d
name
:
CI
on
:
[
push
,
pull_request
]
env
:
BINARY_PREFIX
:
"
go-cqhttp_"
BINARY_SUFFIX
:
"
"
PR_PROMPT
:
"
::warning::
Build
artifact
will
not
be
uploaded
due
to
the
workflow
is
trigged
by
pull
request."
LD_FLAGS
:
"
-w
-s"
jobs
:
build
:
name
:
Build binary CI
runs-on
:
ubuntu-latest
strategy
:
matrix
:
# build and publish in parallel: linux/386, linux/amd64, windows/386, windows/amd64, darwin/386, darwin/amd64
goos
:
[
linux
,
windows
,
darwin
]
goarch
:
[
"
386"
,
amd64
,
arm
]
exclude
:
-
goos
:
darwin
goarch
:
arm
fail-fast
:
true
steps
:
-
uses
:
actions/checkout@v2
-
name
:
Setup Go environment
uses
:
actions/setup-go@v2.1.1
with
:
go-version
:
1.14
-
name
:
Build binary file
env
:
GOOS
:
${{ matrix.goos }}
GOARCH
:
${{ matrix.goarch }}
IS_PR
:
${{ !!github.head_ref }}
run
:
|
if [ $GOOS = "windows" ]; then export BINARY_SUFFIX="$BINARY_SUFFIX.exe"; fi
if $IS_PR ; then echo $PR_PROMPT; fi
export BINARY_NAME="$BINARY_PREFIX$GOOS_$GOARCH$BINARY_SUFFIX"
export CGO_ENABLED=0
go build -o "output/$BINARY_NAME" -ldflags "$LD_FLAGS" .
-
name
:
Upload artifact
uses
:
actions/upload-artifact@v2
if
:
${{ !github.head_ref }}
with
:
name
:
${{ matrix.goos }}_${{ matrix.goarch }}
path
:
output/
.github/workflows/release.yml
View file @
1896043d
...
@@ -11,6 +11,10 @@ jobs:
...
@@ -11,6 +11,10 @@ jobs:
# build and publish in parallel: linux/386, linux/amd64, windows/386, windows/amd64, darwin/386, darwin/amd64
# build and publish in parallel: linux/386, linux/amd64, windows/386, windows/amd64, darwin/386, darwin/amd64
goos
:
[
linux
,
windows
,
darwin
]
goos
:
[
linux
,
windows
,
darwin
]
goarch
:
[
"
386"
,
amd64
,
arm
]
goarch
:
[
"
386"
,
amd64
,
arm
]
exclude
:
-
goos
:
darwin
goarch
:
arm
steps
:
steps
:
-
uses
:
actions/checkout@v2
-
uses
:
actions/checkout@v2
-
uses
:
wangyoucao577/go-release-action@master
-
uses
:
wangyoucao577/go-release-action@master
...
...
LICENSE
View file @
1896043d
This diff is collapsed.
Click to expand it.
coolq/api.go
View file @
1896043d
...
@@ -362,12 +362,14 @@ func (bot *CQBot) CQHandleQuickOperation(context, operation gjson.Result) MSG {
...
@@ -362,12 +362,14 @@ 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
()
{
at
:=
true
/*
if
operation
.
Get
(
"at_sender"
)
.
Exists
()
{
at := true
at
=
operation
.
Get
(
"at_sender"
)
.
Bool
()
if operation.Get("at_sender").Exists() {
}
at = operation.Get("at_sender").Bool()
}
*/
// TODO: 处理at字段
// TODO: 处理at字段
if
msgType
==
"group"
&&
at
{
if
msgType
==
"group"
{
bot
.
CQSendGroupMessage
(
context
.
Get
(
"group_id"
)
.
Int
(),
reply
)
bot
.
CQSendGroupMessage
(
context
.
Get
(
"group_id"
)
.
Int
(),
reply
)
}
}
if
msgType
==
"private"
{
if
msgType
==
"private"
{
...
...
coolq/bot.go
View file @
1896043d
...
@@ -136,16 +136,18 @@ func (bot *CQBot) InsertGroupMessage(m *message.GroupMessage) int32 {
...
@@ -136,16 +136,18 @@ func (bot *CQBot) InsertGroupMessage(m *message.GroupMessage) int32 {
"message"
:
ToStringMessage
(
m
.
Elements
,
m
.
GroupCode
,
true
),
"message"
:
ToStringMessage
(
m
.
Elements
,
m
.
GroupCode
,
true
),
}
}
id
:=
ToGlobalId
(
m
.
GroupCode
,
m
.
Id
)
id
:=
ToGlobalId
(
m
.
GroupCode
,
m
.
Id
)
err
:=
bot
.
db
.
Update
(
func
(
tx
*
nutsdb
.
Tx
)
error
{
if
bot
.
db
!=
nil
{
buf
:=
new
(
bytes
.
Buffer
)
err
:=
bot
.
db
.
Update
(
func
(
tx
*
nutsdb
.
Tx
)
error
{
if
err
:=
gob
.
NewEncoder
(
buf
)
.
Encode
(
val
);
err
!=
nil
{
buf
:=
new
(
bytes
.
Buffer
)
return
err
if
err
:=
gob
.
NewEncoder
(
buf
)
.
Encode
(
val
);
err
!=
nil
{
return
err
}
return
tx
.
Put
(
"group-messages"
,
binary
.
ToBytes
(
id
),
binary
.
GZipCompress
(
buf
.
Bytes
()),
0
)
})
if
err
!=
nil
{
log
.
Warnf
(
"记录聊天数据时出现错误: %v"
,
err
)
return
-
1
}
}
return
tx
.
Put
(
"group-messages"
,
binary
.
ToBytes
(
id
),
binary
.
GZipCompress
(
buf
.
Bytes
()),
0
)
})
if
err
!=
nil
{
log
.
Warnf
(
"记录聊天数据时出现错误: %v"
,
err
)
return
-
1
}
}
return
id
return
id
}
}
...
...
coolq/cqcode.go
View file @
1896043d
...
@@ -10,8 +10,10 @@ import (
...
@@ -10,8 +10,10 @@ import (
log
"github.com/sirupsen/logrus"
log
"github.com/sirupsen/logrus"
"github.com/tidwall/gjson"
"github.com/tidwall/gjson"
"io/ioutil"
"io/ioutil"
"net/url"
"path"
"path"
"regexp"
"regexp"
"runtime"
"strconv"
"strconv"
"strings"
"strings"
)
)
...
@@ -176,6 +178,20 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message.
...
@@ -176,6 +178,20 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message.
}
}
return
message
.
NewImage
(
b
),
nil
return
message
.
NewImage
(
b
),
nil
}
}
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
:
]
}
b
,
err
:=
ioutil
.
ReadFile
(
fu
.
Path
)
if
err
!=
nil
{
return
nil
,
err
}
return
message
.
NewImage
(
b
),
nil
}
if
global
.
PathExists
(
path
.
Join
(
global
.
IMAGE_PATH
,
f
))
{
if
global
.
PathExists
(
path
.
Join
(
global
.
IMAGE_PATH
,
f
))
{
b
,
err
:=
ioutil
.
ReadFile
(
path
.
Join
(
global
.
IMAGE_PATH
,
f
))
b
,
err
:=
ioutil
.
ReadFile
(
path
.
Join
(
global
.
IMAGE_PATH
,
f
))
if
err
!=
nil
{
if
err
!=
nil
{
...
...
coolq/event.go
View file @
1896043d
...
@@ -53,6 +53,7 @@ func (bot *CQBot) groupMessageEvent(c *client.QQClient, m *message.GroupMessage)
...
@@ -53,6 +53,7 @@ func (bot *CQBot) groupMessageEvent(c *client.QQClient, m *message.GroupMessage)
"name"
:
file
.
Name
,
"name"
:
file
.
Name
,
"size"
:
file
.
Size
,
"size"
:
file
.
Size
,
"busid"
:
file
.
Busid
,
"busid"
:
file
.
Busid
,
"url"
:
c
.
GetGroupFileUrl
(
m
.
GroupCode
,
file
.
Path
,
file
.
Busid
),
},
},
"self_id"
:
c
.
Uin
,
"self_id"
:
c
.
Uin
,
"time"
:
time
.
Now
()
.
Unix
(),
"time"
:
time
.
Now
()
.
Unix
(),
...
...
global/config.go
View file @
1896043d
...
@@ -99,7 +99,7 @@ func Load(p string) *JsonConfig {
...
@@ -99,7 +99,7 @@ func Load(p string) *JsonConfig {
}
}
func
(
c
*
JsonConfig
)
Save
(
p
string
)
error
{
func
(
c
*
JsonConfig
)
Save
(
p
string
)
error
{
data
,
err
:=
json
.
Marshal
(
c
)
data
,
err
:=
json
.
Marshal
Indent
(
c
,
""
,
"
\t
"
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
...
go.mod
View file @
1896043d
...
@@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp
...
@@ -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-2020080
2045511-04aad9705bdc
github.com/Mrs4s/MiraiGo v0.0.0-2020080
4064012-e1e00ed0683b
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
...
@@ -15,7 +15,6 @@ require (
...
@@ -15,7 +15,6 @@ require (
github.com/tidwall/gjson v1.6.0
github.com/tidwall/gjson v1.6.0
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/image v0.0.0-20200618115811-c13761719519
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae // indirect
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae // indirect
)
)
go.sum
View file @
1896043d
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-2020080
2045511-04aad9705bdc h1:mtPgcLy1VNr+nTA7vQibBYpYpFALJ+ChVkUwA8KNKfI
=
github.com/Mrs4s/MiraiGo v0.0.0-2020080
4064012-e1e00ed0683b h1:HBZgam4cS+6/XFVXVcEv3YINozw2qUjnZIhj6EQXLbU
=
github.com/Mrs4s/MiraiGo v0.0.0-2020080
2045511-04aad9705bdc
/go.mod h1:M9wh1hjd0rie3+wm27tjPZkYMbD+MBV76CGqp2G7WSU=
github.com/Mrs4s/MiraiGo v0.0.0-2020080
4064012-e1e00ed0683b
/go.mod h1:M9wh1hjd0rie3+wm27tjPZkYMbD+MBV76CGqp2G7WSU=
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=
...
@@ -50,7 +50,6 @@ github.com/guonaihong/gout v0.1.1/go.mod h1:vXvv5Kxr70eM5wrp4F0+t9lnLWmq+YPW2GBy
...
@@ -50,7 +50,6 @@ github.com/guonaihong/gout v0.1.1/go.mod h1:vXvv5Kxr70eM5wrp4F0+t9lnLWmq+YPW2GBy
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8=
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw=
github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw=
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
...
@@ -103,7 +102,6 @@ github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189 h1:4UJw9if5
...
@@ -103,7 +102,6 @@ github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189 h1:4UJw9if5
github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189/go.mod h1:rIrm5geMiBhPQkdfUm8gDFi/WiHneOp1i9KjmJqc+9I=
github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189/go.mod h1:rIrm5geMiBhPQkdfUm8gDFi/WiHneOp1i9KjmJqc+9I=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/image v0.0.0-20200618115811-c13761719519/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
...
...
server/websocket.go
View file @
1896043d
...
@@ -157,12 +157,12 @@ func (c *websocketClient) connectUniversal() {
...
@@ -157,12 +157,12 @@ func (c *websocketClient) connectUniversal() {
func
(
c
*
websocketClient
)
listenApi
(
conn
*
wsc
.
Conn
,
u
bool
)
{
func
(
c
*
websocketClient
)
listenApi
(
conn
*
wsc
.
Conn
,
u
bool
)
{
defer
conn
.
Close
()
defer
conn
.
Close
()
for
{
for
{
buf
:=
make
([]
byte
,
10240
)
var
buf
[]
byte
l
,
err
:=
conn
.
Read
(
buf
)
err
:=
wsc
.
Message
.
Receive
(
conn
,
&
buf
)
if
err
!=
nil
{
if
err
!=
nil
{
break
break
}
}
j
:=
gjson
.
ParseBytes
(
buf
[
:
l
]
)
j
:=
gjson
.
ParseBytes
(
buf
)
t
:=
strings
.
ReplaceAll
(
j
.
Get
(
"action"
)
.
Str
,
"_async"
,
""
)
t
:=
strings
.
ReplaceAll
(
j
.
Get
(
"action"
)
.
Str
,
"_async"
,
""
)
log
.
Debugf
(
"反向WS接收到API调用: %v 参数: %v"
,
t
,
j
.
Get
(
"params"
)
.
Raw
)
log
.
Debugf
(
"反向WS接收到API调用: %v 参数: %v"
,
t
,
j
.
Get
(
"params"
)
.
Raw
)
if
f
,
ok
:=
wsApi
[
t
];
ok
{
if
f
,
ok
:=
wsApi
[
t
];
ok
{
...
...
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