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
cd882278
Commit
cd882278
authored
Aug 07, 2020
by
nanahira
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of github.com:Mrs4s/go-cqhttp
parents
1896043d
2ec7f83d
Pipeline
#486
passed with stages
in 6 minutes and 7 seconds
Changes
7
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
53 additions
and
18 deletions
+53
-18
.github/workflows/release.yml
.github/workflows/release.yml
+2
-0
coolq/api.go
coolq/api.go
+6
-0
coolq/cqcode.go
coolq/cqcode.go
+27
-6
go.mod
go.mod
+1
-1
go.sum
go.sum
+6
-3
main.go
main.go
+4
-2
server/http.go
server/http.go
+7
-6
No files found.
.github/workflows/release.yml
View file @
cd882278
...
...
@@ -18,6 +18,8 @@ jobs:
steps
:
-
uses
:
actions/checkout@v2
-
uses
:
wangyoucao577/go-release-action@master
env
:
CGO_ENABLED
:
0
with
:
github_token
:
${{ secrets.GITHUB_TOKEN }}
goos
:
${{ matrix.goos }}
...
...
coolq/api.go
View file @
cd882278
...
...
@@ -121,6 +121,12 @@ func (bot *CQBot) CQSendGroupMessage(groupId int64, i interface{}) MSG {
return
Failed
(
100
)
}
elem
:=
bot
.
ConvertStringMessage
(
str
,
true
)
// fix at display
for
_
,
e
:=
range
elem
{
if
at
,
ok
:=
e
.
(
*
message
.
AtElement
);
ok
&&
at
.
Target
!=
0
{
at
.
Display
=
"@"
+
bot
.
Client
.
FindGroup
(
groupId
)
.
FindMember
(
at
.
Target
)
.
DisplayName
()
}
}
mid
:=
bot
.
SendGroupMessage
(
groupId
,
&
message
.
SendingMessage
{
Elements
:
elem
})
if
mid
==
-
1
{
return
Failed
(
100
)
...
...
coolq/cqcode.go
View file @
cd882278
...
...
@@ -2,6 +2,7 @@ package coolq
import
(
"encoding/base64"
"encoding/hex"
"errors"
"fmt"
"github.com/Mrs4s/MiraiGo/binary"
...
...
@@ -192,24 +193,44 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message.
}
return
message
.
NewImage
(
b
),
nil
}
if
global
.
PathExists
(
path
.
Join
(
global
.
IMAGE_PATH
,
f
))
{
b
,
err
:=
ioutil
.
ReadFile
(
path
.
Join
(
global
.
IMAGE_PATH
,
f
))
rawPath
:=
path
.
Join
(
global
.
IMAGE_PATH
,
f
)
if
global
.
PathExists
(
rawPath
)
{
b
,
err
:=
ioutil
.
ReadFile
(
rawPath
)
if
err
!=
nil
{
return
nil
,
err
}
if
path
.
Ext
(
rawPath
)
!=
".image"
{
return
message
.
NewImage
(
b
),
nil
}
if
len
(
b
)
<
20
{
return
nil
,
errors
.
New
(
"invalid local file"
)
}
var
size
int32
var
hash
[]
byte
if
path
.
Ext
(
rawPath
)
==
".cqimg"
{
for
_
,
line
:=
range
strings
.
Split
(
global
.
ReadAllText
(
rawPath
),
"
\n
"
)
{
kv
:=
strings
.
SplitN
(
line
,
"="
,
2
)
switch
kv
[
0
]
{
case
"md5"
:
hash
,
_
=
hex
.
DecodeString
(
kv
[
1
])
case
"size"
:
t
,
_
:=
strconv
.
Atoi
(
kv
[
1
])
size
=
int32
(
t
)
}
}
}
else
{
r
:=
binary
.
NewReader
(
b
)
hash
:=
r
.
ReadBytes
(
16
)
hash
=
r
.
ReadBytes
(
16
)
size
=
r
.
ReadInt32
()
}
if
group
{
rsp
,
err
:=
bot
.
Client
.
QueryGroupImage
(
1
,
hash
,
r
.
ReadInt32
()
)
rsp
,
err
:=
bot
.
Client
.
QueryGroupImage
(
1
,
hash
,
size
)
if
err
!=
nil
{
return
nil
,
err
}
return
rsp
,
nil
}
rsp
,
err
:=
bot
.
Client
.
QueryFriendImage
(
1
,
hash
,
r
.
ReadInt32
()
)
rsp
,
err
:=
bot
.
Client
.
QueryFriendImage
(
1
,
hash
,
size
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
go.mod
View file @
cd882278
...
...
@@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp
go 1.14
require (
github.com/Mrs4s/MiraiGo v0.0.0-2020080
4064012-e1e00ed0683b
github.com/Mrs4s/MiraiGo v0.0.0-2020080
7030850-ed30f7ad5934
github.com/gin-gonic/gin v1.6.3
github.com/gorilla/websocket v1.4.2
github.com/guonaihong/gout v0.1.1
...
...
go.sum
View file @
cd882278
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/Mrs4s/MiraiGo v0.0.0-2020080
4064012-e1e00ed0683b h1:HBZgam4cS+6/XFVXVcEv3YINozw2qUjnZIhj6EQXLbU
=
github.com/Mrs4s/MiraiGo v0.0.0-2020080
4064012-e1e00ed0683b/go.mod h1:M9wh1hjd0rie3+wm27tjPZkYMbD+MBV76CGqp2G7WSU
=
github.com/Mrs4s/MiraiGo v0.0.0-2020080
7030850-ed30f7ad5934 h1:LoNjIsnyEQFGP9IchIQ65yHRCfNKSru3BAOguRepkCM
=
github.com/Mrs4s/MiraiGo v0.0.0-2020080
7030850-ed30f7ad5934/go.mod h1:0je03wji/tSw4bUH4QCF2Z4/EjyNWjSJTyy5tliX6EM
=
github.com/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0=
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=
...
...
@@ -34,8 +34,9 @@ github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:x
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/golang/protobuf v1.4.1 h1:ZFgWrT+bLgsYPirOnRfKLYJLvssAegOj/hgyMFdJZe0=
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0=
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
...
...
@@ -50,6 +51,7 @@ 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.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.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8=
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.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
...
...
@@ -145,6 +147,7 @@ google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQ
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c=
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
...
...
main.go
View file @
cd882278
...
...
@@ -158,12 +158,14 @@ func main() {
case
client
.
NeedCaptcha
:
img
,
_
,
_
:=
image
.
Decode
(
bytes
.
NewReader
(
rsp
.
CaptchaImage
))
fmt
.
Println
(
asciiart
.
New
(
"image"
,
img
)
.
Art
)
log
.
Warn
(
"请输入验证码: (
回车
提交)"
)
log
.
Warn
(
"请输入验证码: (
Enter
提交)"
)
text
,
_
:=
console
.
ReadString
(
'\n'
)
rsp
,
err
=
cli
.
SubmitCaptcha
(
strings
.
ReplaceAll
(
text
,
"
\n
"
,
""
),
rsp
.
CaptchaSign
)
continue
case
client
.
UnsafeDeviceError
:
log
.
Warnf
(
"账号已开启设备锁,请前往 -> %v <- 验证并重启Bot."
,
rsp
.
VerifyUrl
)
log
.
Infof
(
" 按 Enter 继续...."
)
_
,
_
=
console
.
ReadString
(
'\n'
)
return
case
client
.
OtherLoginError
,
client
.
UnknownLoginError
:
log
.
Fatalf
(
"登录失败: %v"
,
rsp
.
ErrorMessage
)
...
...
@@ -196,7 +198,7 @@ func main() {
log
.
Info
(
"アトリは、高性能ですから!"
)
cli
.
OnDisconnected
(
func
(
bot
*
client
.
QQClient
,
e
*
client
.
ClientDisconnectedEvent
)
{
if
conf
.
ReLogin
{
log
.
Warnf
(
"Bot已离线
,将在 %v 秒后尝试重连."
,
conf
.
ReLoginDelay
)
log
.
Warnf
(
"Bot已离线
(%v),将在 %v 秒后尝试重连."
,
e
.
Message
,
conf
.
ReLoginDelay
)
time
.
Sleep
(
time
.
Second
*
time
.
Duration
(
conf
.
ReLoginDelay
))
rsp
,
err
:=
cli
.
Login
()
if
err
!=
nil
{
...
...
server/http.go
View file @
cd882278
...
...
@@ -4,14 +4,15 @@ import (
"crypto/hmac"
"crypto/sha1"
"encoding/hex"
"strconv"
"strings"
"time"
"github.com/Mrs4s/go-cqhttp/coolq"
"github.com/gin-gonic/gin"
"github.com/guonaihong/gout"
log
"github.com/sirupsen/logrus"
"github.com/tidwall/gjson"
"strconv"
"strings"
"time"
)
type
httpServer
struct
{
...
...
@@ -61,12 +62,12 @@ func (s *httpServer) Run(addr, authToken string, bot *coolq.CQBot) {
c
.
AbortWithStatus
(
401
)
return
}
}
if
c
.
Query
(
"access_token"
)
!=
authToken
{
}
else
if
c
.
Query
(
"access_token"
)
!=
authToken
{
c
.
AbortWithStatus
(
401
)
return
}
}
else
{
c
.
Next
()
}
})
}
...
...
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