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
d2d408a8
Commit
d2d408a8
authored
Sep 22, 2020
by
wdvxdr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feature set_group_portrait
[2020-09-22 10:50:46] [ERROR]: 读取服务器地址时出现错误: %vEOF
parent
995737b0
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
78 additions
and
4 deletions
+78
-4
coolq/api.go
coolq/api.go
+13
-0
global/fs.go
global/fs.go
+50
-2
go.mod
go.mod
+1
-1
main.go
main.go
+1
-1
server/http.go
server/http.go
+10
-0
server/websocket.go
server/websocket.go
+3
-0
No files found.
coolq/api.go
View file @
d2d408a8
...
...
@@ -667,6 +667,19 @@ func (bot *CQBot) CQReloadEventFilter() MSG {
return
OK
(
nil
)
}
func
(
bot
*
CQBot
)
CQSetGroupPortrait
(
groupId
int64
,
file
,
cache
string
)
MSG
{
if
g
:=
bot
.
Client
.
FindGroup
(
groupId
);
g
!=
nil
{
img
,
err
:=
global
.
FindFile
(
file
,
cache
,
global
.
IMAGE_PATH
)
if
err
!=
nil
{
log
.
Warnf
(
"set group portrait error: %v"
,
err
)
return
Failed
(
100
)
}
g
.
UpdateGroupHeadPortrait
(
img
)
return
OK
(
nil
)
}
return
Failed
(
100
)
}
func
(
bot
*
CQBot
)
CQGetStatus
()
MSG
{
return
OK
(
MSG
{
"app_initialized"
:
true
,
...
...
global/fs.go
View file @
d2d408a8
...
...
@@ -2,11 +2,17 @@ package global
import
(
"bytes"
"crypto/md5"
"encoding/base64"
"encoding/hex"
"errors"
log
"github.com/sirupsen/logrus"
"io/ioutil"
"net/url"
"os"
"path"
log
"github.com/sirupsen/logru
s"
"runtime"
"string
s"
)
var
(
...
...
@@ -45,3 +51,45 @@ func Check(err error) {
func
IsAMRorSILK
(
b
[]
byte
)
bool
{
return
bytes
.
HasPrefix
(
b
,
HEADER_AMR
)
||
bytes
.
HasPrefix
(
b
,
HEADER_SILK
)
}
func
FindFile
(
f
,
cache
,
PATH
string
)
(
data
[]
byte
,
err
error
)
{
data
,
err
=
nil
,
errors
.
New
(
"can't find the file: "
+
f
)
if
strings
.
HasPrefix
(
f
,
"http"
)
||
strings
.
HasPrefix
(
f
,
"https"
)
{
if
cache
==
""
{
cache
=
"1"
}
hash
:=
md5
.
Sum
([]
byte
(
f
))
cacheFile
:=
path
.
Join
(
CACHE_PATH
,
hex
.
EncodeToString
(
hash
[
:
])
+
".cache"
)
if
PathExists
(
cacheFile
)
&&
cache
==
"1"
{
return
ioutil
.
ReadFile
(
cacheFile
)
}
data
,
err
=
GetBytes
(
f
)
_
=
ioutil
.
WriteFile
(
cacheFile
,
data
,
0644
)
if
err
!=
nil
{
return
nil
,
err
}
}
else
if
strings
.
HasPrefix
(
f
,
"base64"
)
{
data
,
err
=
base64
.
StdEncoding
.
DecodeString
(
strings
.
ReplaceAll
(
f
,
"base64://"
,
""
))
if
err
!=
nil
{
return
nil
,
err
}
}
else
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
:
]
}
data
,
err
=
ioutil
.
ReadFile
(
fu
.
Path
)
if
err
!=
nil
{
return
nil
,
err
}
}
else
if
PathExists
(
path
.
Join
(
PATH
,
f
))
{
data
,
err
=
ioutil
.
ReadFile
(
path
.
Join
(
PATH
,
f
))
if
err
!=
nil
{
return
nil
,
err
}
}
return
}
go.mod
View file @
d2d408a8
...
...
@@ -25,7 +25,7 @@ require (
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-20200904194848-62affa334b73 // indirect
golang.org/x/sys v0.0.0-202009
09081042-eff7692f9009
// indirect
golang.org/x/sys v0.0.0-202009
16084744-dbad9cb7cb7a
// indirect
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e
gopkg.in/yaml.v2 v2.3.0 // indirect
)
main.go
View file @
d2d408a8
...
...
@@ -260,7 +260,7 @@ func main() {
func
()
{
defer
func
()
{
if
pan
:=
recover
();
pan
!=
nil
{
log
.
Error
(
"读取服务器地址时出现错误:
%v
"
,
pan
)
log
.
Error
(
"读取服务器地址时出现错误: "
,
pan
)
}
}()
r
:=
binary
.
NewReader
(
data
)
...
...
server/http.go
View file @
d2d408a8
...
...
@@ -354,6 +354,13 @@ func (s *httpServer) OcrImage(c *gin.Context) {
c
.
JSON
(
200
,
s
.
bot
.
CQOcrImage
(
img
))
}
func
(
s
*
httpServer
)
SetGroupPortrait
(
c
*
gin
.
Context
)
{
gid
,
_
:=
strconv
.
ParseInt
(
getParam
(
c
,
"group_id"
),
10
,
64
)
file
:=
getParam
(
c
,
"file"
)
cache
:=
getParam
(
c
,
"cache"
)
c
.
JSON
(
200
,
s
.
bot
.
CQSetGroupPortrait
(
gid
,
file
,
cache
))
}
func
getParamOrDefault
(
c
*
gin
.
Context
,
k
,
def
string
)
string
{
r
:=
getParam
(
c
,
k
)
if
r
!=
""
{
...
...
@@ -502,6 +509,9 @@ var httpApi = map[string]func(s *httpServer, c *gin.Context){
"reload_event_filter"
:
func
(
s
*
httpServer
,
c
*
gin
.
Context
)
{
s
.
ReloadEventFilter
(
c
)
},
"set_group_portrait"
:
func
(
s
*
httpServer
,
c
*
gin
.
Context
)
{
s
.
SetGroupPortrait
(
c
)
},
".handle_quick_operation"
:
func
(
s
*
httpServer
,
c
*
gin
.
Context
)
{
s
.
HandleQuickOperation
(
c
)
},
...
...
server/websocket.go
View file @
d2d408a8
...
...
@@ -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
)
},
"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
())
},
".handle_quick_operation"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
coolq
.
MSG
{
return
bot
.
CQHandleQuickOperation
(
p
.
Get
(
"context"
),
p
.
Get
(
"operation"
))
},
...
...
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