可自定义配置文件路径,修改推送消息
This commit is contained in:
parent
fa214721cd
commit
050ab4ed41
|
@ -90,28 +90,39 @@ var (
|
|||
//go:embed config_default.yml
|
||||
var defaultConfig []byte
|
||||
|
||||
// SetVersion
|
||||
/* @Description: 设置应用程序版本号
|
||||
* @param string2
|
||||
*/
|
||||
func SetVersion(string2 string) {
|
||||
config.version = string2
|
||||
}
|
||||
|
||||
// GetVersion
|
||||
/* @Description: 获取应用程序版本号
|
||||
* @return string
|
||||
*/
|
||||
func GetVersion() string {
|
||||
return config.version
|
||||
}
|
||||
|
||||
// GetConfig
|
||||
/**
|
||||
* @Description:
|
||||
* @return Config
|
||||
// InitConfig
|
||||
/* @Description: 初始化配置文件
|
||||
* @param path
|
||||
*/
|
||||
func GetConfig() Config {
|
||||
file, err := os.ReadFile("./config/config.yml")
|
||||
func InitConfig(path string) {
|
||||
if path == "" {
|
||||
path = "./config/config.yml"
|
||||
}
|
||||
log.Infoln("配置文件路径 ==》 " + path)
|
||||
file, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
log.Warningln("检测到配置文件可能不存在")
|
||||
err := os.WriteFile("./config/config.yml", defaultConfig, 0666)
|
||||
err := os.WriteFile(path, defaultConfig, 0666)
|
||||
if err != nil {
|
||||
log.Errorln("写入到配置文件出现错误")
|
||||
log.Errorln(err.Error())
|
||||
return Config{}
|
||||
return
|
||||
}
|
||||
log.Infoln("成功写入到配置文件,请重启应用")
|
||||
os.Exit(3)
|
||||
|
@ -119,7 +130,7 @@ func GetConfig() Config {
|
|||
err = yaml.Unmarshal(file, &config)
|
||||
if err != nil {
|
||||
log.Errorln(err.Error())
|
||||
return Config{}
|
||||
log.Panicln("配置文件解析失败,请检查配置文件")
|
||||
}
|
||||
if config.Scheme == "" {
|
||||
config.Scheme = "https://johlanse.github.io/study_xxqg/scheme.html?"
|
||||
|
@ -130,5 +141,13 @@ func GetConfig() Config {
|
|||
if config.TG.CustomApi == "" {
|
||||
config.TG.CustomApi = "https://api.telegram.org"
|
||||
}
|
||||
}
|
||||
|
||||
// GetConfig
|
||||
/**
|
||||
* @Description: 获取配置信息
|
||||
* @return Config
|
||||
*/
|
||||
func GetConfig() Config {
|
||||
return config
|
||||
}
|
||||
|
|
|
@ -273,7 +273,7 @@ func studyAll(bot *Telegram, args []string) {
|
|||
select {
|
||||
case <-timer:
|
||||
{
|
||||
bot.SendMsg("学习超时,请重新登录或检查日志")
|
||||
bot.SendMsg("学习超时,请重新学习或检查日志")
|
||||
log.Errorln("学习超时,已自动退出")
|
||||
core.Quit()
|
||||
}
|
||||
|
@ -282,7 +282,7 @@ func studyAll(bot *Telegram, args []string) {
|
|||
}
|
||||
}
|
||||
score, _ := GetUserScore(user.ToCookies())
|
||||
bot.SendMsg(fmt.Sprintf("当前学习总积分:%v,今日得分:%v", score.TotalScore, score.TodayScore))
|
||||
bot.SendMsg(fmt.Sprintf("%v已学习完成\n%v", user.Nick, PrintScore(score)))
|
||||
}
|
||||
s()
|
||||
}
|
||||
|
@ -379,7 +379,7 @@ func study(bot *Telegram, args []string) {
|
|||
}
|
||||
}
|
||||
score, _ := GetUserScore(user.ToCookies())
|
||||
bot.SendMsg(fmt.Sprintf("当前学习总积分:%v,今日得分:%v", score.TotalScore, score.TodayScore))
|
||||
bot.SendMsg(fmt.Sprintf("%v已学习完成\n%v", user.Nick, PrintScore(score)))
|
||||
}
|
||||
|
||||
func getScores(bot *Telegram, args []string) {
|
||||
|
|
17
main.go
17
main.go
|
@ -27,17 +27,20 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
u bool
|
||||
i bool
|
||||
u bool
|
||||
i bool
|
||||
configPath = ""
|
||||
)
|
||||
|
||||
var VERSION = "unknown"
|
||||
|
||||
func init() {
|
||||
flag.BoolVar(&u, "u", false, "update the study_xxqg")
|
||||
flag.BoolVar(&u, "u", false, "更新应用")
|
||||
flag.BoolVar(&i, "init", false, "init the app")
|
||||
flag.StringVar(&configPath, "config", "./config/config.yml", "设置配置文件路径")
|
||||
flag.Parse()
|
||||
|
||||
// 初始化配置文件
|
||||
conf.InitConfig(configPath)
|
||||
config = conf.GetConfig()
|
||||
logFormatter := &easy.Formatter{
|
||||
TimestampFormat: "2006-01-02 15:04:05",
|
||||
|
@ -233,7 +236,7 @@ func do(m string) {
|
|||
log.Debugln(err.Error())
|
||||
return
|
||||
}
|
||||
message := u.Nick + " 学习完成:今日得分:" + strconv.Itoa(score.TodayScore)
|
||||
|
||||
score, _ = lib.GetUserScore(user.ToCookies())
|
||||
content := lib.FormatScore(score)
|
||||
err = push.PushMessage(user.Nick+"学习情况", user.Nick+"学习情况"+content, "score", user.PushId)
|
||||
|
@ -241,8 +244,8 @@ func do(m string) {
|
|||
log.Errorln(err.Error())
|
||||
err = nil
|
||||
}
|
||||
core2.Push("markdown", message)
|
||||
core2.Push("flush", "")
|
||||
message := u.Nick + " 学习完成:今日得分:" + lib.PrintScore(score)
|
||||
core2.Push("flush", message)
|
||||
}
|
||||
|
||||
// 用户小于1时自动登录
|
||||
|
|
Loading…
Reference in New Issue