-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
flag.go
135 lines (123 loc) · 4.7 KB
/
flag.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// Package base provides base config for go-cqhttp
package base
import (
"flag"
"fmt"
"os"
"time"
log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v3"
"github.com/Mrs4s/go-cqhttp/modules/config"
)
// command flags
var (
LittleC string // config file
LittleD bool // daemon
LittleH bool // Help
LittleWD string // working directory
)
// config file flags
var (
Debug bool // 是否开启 debug 模式
RemoveReplyAt bool // 是否删除reply后的at
ExtraReplyData bool // 是否上报额外reply信息
IgnoreInvalidCQCode bool // 是否忽略无效CQ码
SplitURL bool // 是否分割URL
ForceFragmented bool // 是否启用强制分片
SkipMimeScan bool // 是否跳过Mime扫描
ConvertWebpImage bool // 是否转换Webp图片
ReportSelfMessage bool // 是否上报自身消息
UseSSOAddress bool // 是否使用服务器下发的新地址进行重连
LogForceNew bool // 是否在每次启动时强制创建全新的文件储存日志
LogColorful bool // 是否启用日志颜色
FastStart bool // 是否为快速启动
AllowTempSession bool // 是否允许发送临时会话信息
UpdateProtocol bool // 是否更新协议
SignServers []config.SignServer // 使用特定的服务器进行签名
IsBelow110 bool // 签名服务器版本是否低于1.1.0及以下
HTTPTimeout int // download 超时时间
SignServerTimeout int // 签名服务器超时时间
PostFormat string // 上报格式 string or array
Proxy string // 存储 proxy_rewrite,用于设置代理
PasswordHash [16]byte // 存储QQ密码哈希供登录使用
AccountToken []byte // 存储 AccountToken 供登录使用
Account *config.Account // 账户配置
Reconnect *config.Reconnect // 重连配置
LogLevel string // 日志等级
LogAging = time.Hour * 24 * 365 // 日志时效
HeartbeatInterval = time.Second * 5 // 心跳间隔
Servers []map[string]yaml.Node // 连接服务列表
Database map[string]yaml.Node // 数据库列表
)
// Parse parse flags
func Parse() {
flag.StringVar(&LittleC, "c", "config.yml", "configuration filename")
flag.BoolVar(&LittleD, "d", false, "running as a daemon")
flag.BoolVar(&LittleH, "h", false, "this Help")
flag.StringVar(&LittleWD, "w", "", "cover the working directory")
d := flag.Bool("D", false, "debug mode")
flag.BoolVar(&FastStart, "faststart", false, "skip waiting 5 seconds")
flag.BoolVar(&UpdateProtocol, "update-protocol", false, "update protocol")
flag.Parse()
if *d {
Debug = true
}
}
// Init read config from yml file
func Init() {
conf := config.Parse(LittleC)
{ // bool config
if conf.Output.Debug {
Debug = true
}
IgnoreInvalidCQCode = conf.Message.IgnoreInvalidCQCode
SplitURL = conf.Message.FixURL
RemoveReplyAt = conf.Message.RemoveReplyAt
ExtraReplyData = conf.Message.ExtraReplyData
ForceFragmented = conf.Message.ForceFragment
SkipMimeScan = conf.Message.SkipMimeScan
ConvertWebpImage = conf.Message.ConvertWebpImage
ReportSelfMessage = conf.Message.ReportSelfMessage
UseSSOAddress = conf.Account.UseSSOAddress
AllowTempSession = conf.Account.AllowTempSession
SignServers = conf.Account.SignServers
IsBelow110 = conf.Account.IsBelow110
HTTPTimeout = conf.Message.HTTPTimeout
SignServerTimeout = int(conf.Account.SignServerTimeout)
}
{ // others
Proxy = conf.Message.ProxyRewrite
Account = conf.Account
Reconnect = conf.Account.ReLogin
Servers = conf.Servers
Database = conf.Database
LogLevel = conf.Output.LogLevel
LogColorful = conf.Output.LogColorful == nil || *conf.Output.LogColorful
if conf.Message.PostFormat != "string" && conf.Message.PostFormat != "array" {
log.Warnf("post-format 配置错误, 将自动使用 string")
PostFormat = "string"
} else {
PostFormat = conf.Message.PostFormat
}
if conf.Output.LogAging > 0 {
LogAging = time.Hour * 24 * time.Duration(conf.Output.LogAging)
}
if conf.Heartbeat.Interval > 0 {
HeartbeatInterval = time.Second * time.Duration(conf.Heartbeat.Interval)
}
if conf.Heartbeat.Disabled || conf.Heartbeat.Interval < 0 {
HeartbeatInterval = 0
}
}
}
// Help cli命令行-h的帮助提示
func Help() {
fmt.Printf(`go-cqhttp service
version: %s
Usage:
server [OPTIONS]
Options:
`, Version)
flag.PrintDefaults()
os.Exit(0)
}