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
2670c84c
Commit
2670c84c
authored
Aug 02, 2020
by
Mrs4s
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
env supported.
parent
e2b6c3d6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
5 deletions
+34
-5
global/config.go
global/config.go
+0
-1
main.go
main.go
+34
-4
No files found.
global/config.go
View file @
2670c84c
...
@@ -15,7 +15,6 @@ type JsonConfig struct {
...
@@ -15,7 +15,6 @@ type JsonConfig struct {
HttpConfig
*
GoCQHttpConfig
`json:"http_config"`
HttpConfig
*
GoCQHttpConfig
`json:"http_config"`
WSConfig
*
GoCQWebsocketConfig
`json:"ws_config"`
WSConfig
*
GoCQWebsocketConfig
`json:"ws_config"`
ReverseServers
[]
*
GoCQReverseWebsocketConfig
`json:"ws_reverse_servers"`
ReverseServers
[]
*
GoCQReverseWebsocketConfig
`json:"ws_reverse_servers"`
Proxy
string
`json:"proxy"`
Debug
bool
`json:"debug"`
Debug
bool
`json:"debug"`
}
}
...
...
main.go
View file @
2670c84c
...
@@ -18,6 +18,7 @@ import (
...
@@ -18,6 +18,7 @@ import (
"os"
"os"
"os/signal"
"os/signal"
"path"
"path"
"strconv"
"strings"
"strings"
"time"
"time"
)
)
...
@@ -72,7 +73,34 @@ func init() {
...
@@ -72,7 +73,34 @@ func init() {
func
main
()
{
func
main
()
{
console
:=
bufio
.
NewReader
(
os
.
Stdin
)
console
:=
bufio
.
NewReader
(
os
.
Stdin
)
conf
:=
global
.
Load
(
"config.json"
)
var
conf
*
global
.
JsonConfig
if
global
.
PathExists
(
"config.json"
)
||
os
.
Getenv
(
"UIN"
)
==
""
{
conf
=
global
.
Load
(
"config.json"
)
}
else
if
os
.
Getenv
(
"UIN"
)
!=
""
{
log
.
Infof
(
"将从环境变量加载配置."
)
uin
,
_
:=
strconv
.
ParseInt
(
os
.
Getenv
(
"UIN"
),
10
,
64
)
pwd
:=
os
.
Getenv
(
"PASS"
)
post
:=
os
.
Getenv
(
"HTTP_POST"
)
conf
=
&
global
.
JsonConfig
{
Uin
:
uin
,
Password
:
pwd
,
HttpConfig
:
&
global
.
GoCQHttpConfig
{
Enabled
:
true
,
Host
:
"0.0.0.0"
,
Port
:
5700
,
PostUrls
:
map
[
string
]
string
{},
},
WSConfig
:
&
global
.
GoCQWebsocketConfig
{
Enabled
:
true
,
Host
:
"0.0.0.0"
,
Port
:
6700
,
},
Debug
:
os
.
Getenv
(
"DEBUG"
)
==
"true"
,
}
if
post
!=
""
{
conf
.
HttpConfig
.
PostUrls
[
post
]
=
os
.
Getenv
(
"HTTP_SECRET"
)
}
}
if
conf
==
nil
{
if
conf
==
nil
{
err
:=
global
.
DefaultConfig
()
.
Save
(
"config.json"
)
err
:=
global
.
DefaultConfig
()
.
Save
(
"config.json"
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -80,18 +108,20 @@ func main() {
...
@@ -80,18 +108,20 @@ func main() {
return
return
}
}
log
.
Infof
(
"默认配置文件已生成, 请编辑 config.json 后重启程序."
)
log
.
Infof
(
"默认配置文件已生成, 请编辑 config.json 后重启程序."
)
time
.
Sleep
(
time
.
Second
*
5
)
return
return
}
}
if
conf
.
Uin
==
0
||
conf
.
Password
==
""
{
if
conf
.
Uin
==
0
||
conf
.
Password
==
""
{
log
.
Fatal
(
"请修改 config.json 以添加账号密码."
)
log
.
Warnf
(
"请修改 config.json 以添加账号密码."
)
time
.
Sleep
(
time
.
Second
*
5
)
return
}
}
if
conf
.
Debug
{
if
conf
.
Debug
{
log
.
SetLevel
(
log
.
DebugLevel
)
log
.
SetLevel
(
log
.
DebugLevel
)
log
.
Warnf
(
"已开启Debug模式."
)
log
.
Warnf
(
"已开启Debug模式."
)
}
}
if
!
global
.
PathExists
(
"device.json"
)
{
if
!
global
.
PathExists
(
"device.json"
)
{
log
.
Warn
(
"虚拟设备信息不存在, 将自动生成随机设备,按 Enter 继续."
)
log
.
Warn
(
"虚拟设备信息不存在, 将自动生成随机设备."
)
_
,
_
=
console
.
ReadString
(
'\n'
)
client
.
GenRandomDevice
()
client
.
GenRandomDevice
()
_
=
ioutil
.
WriteFile
(
"device.json"
,
client
.
SystemDeviceInfo
.
ToJson
(),
0777
)
_
=
ioutil
.
WriteFile
(
"device.json"
,
client
.
SystemDeviceInfo
.
ToJson
(),
0777
)
log
.
Info
(
"已生成设备信息并保存到 device.json 文件."
)
log
.
Info
(
"已生成设备信息并保存到 device.json 文件."
)
...
...
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