fix errconfig

This commit is contained in:
Evan 2022-12-16 19:12:35 +09:00
parent 763b818036
commit 1485aeef47
3 changed files with 31 additions and 16 deletions

View File

@ -72,8 +72,6 @@ xiaomoinfo/wechatgpt:latest
`警告:以下命令会让任何消息都会被机器人接管,微信主号不要用下面这个命令` `警告:以下命令会让任何消息都会被机器人接管,微信主号不要用下面这个命令`
``` ```
# linux amd64
docker run -d \ docker run -d \
--name wechatgpt \ --name wechatgpt \
-e api_key="你的chatgpt api_key" \ -e api_key="你的chatgpt api_key" \
@ -85,7 +83,6 @@ xiaomoinfo/wechatgpt:latest
运行`telegram`智能机器人的话运行下面这段代码 运行`telegram`智能机器人的话运行下面这段代码
``` ```
# linux amd64
docker run -d \ docker run -d \
--name wechatgpt \ --name wechatgpt \
-e api_key="你的chatgpt api_key" \ -e api_key="你的chatgpt api_key" \
@ -97,7 +94,6 @@ xiaomoinfo/wechatgpt:latest
如果运行`telegram`智能机器人时只希望指定的人使用,白名单以外的人发消息机器人不会回复 如果运行`telegram`智能机器人时只希望指定的人使用,白名单以外的人发消息机器人不会回复
``` ```
# linux amd64
docker run -d \ docker run -d \
--name wechatgpt \ --name wechatgpt \
-e api_key="你的chatgpt api_key" \ -e api_key="你的chatgpt api_key" \
@ -110,7 +106,6 @@ xiaomoinfo/wechatgpt:latest
如果运行`telegram`智能机器人时希望在群里回复别人消息,可以指定一个关键字触发 如果运行`telegram`智能机器人时希望在群里回复别人消息,可以指定一个关键字触发
``` ```
# linux amd64
docker run -d \ docker run -d \
--name wechatgpt \ --name wechatgpt \
-e api_key="你的chatgpt api_key" \ -e api_key="你的chatgpt api_key" \

View File

@ -14,12 +14,3 @@ tasks:
cmds: cmds:
- docker build --platform linux/amd64 -t xiaomoinfo/wechatgpt-amd64:latest . - docker build --platform linux/amd64 -t xiaomoinfo/wechatgpt-amd64:latest .
- docker push xiaomoinfo/wechatgpt-amd64:latest - docker push xiaomoinfo/wechatgpt-amd64:latest
- docker build -t xiaomoinfo/wechatgpt:latest .
- docker push xiaomoinfo/wechatgpt:latest
version:
cmds:
- docker build --platform linux/amd64 -t xiaomoinfo/wechatgpt-amd64:2.9.2 .
- docker push xiaomoinfo/wechatgpt-amd64:2.9.2
- docker build -t xiaomoinfo/wechatgpt:2.9.2 .
- docker push xiaomoinfo/wechatgpt:2.9.2

View File

@ -1,6 +1,7 @@
package config package config
import ( import (
"fmt"
"github.com/spf13/viper" "github.com/spf13/viper"
"os" "os"
"strings" "strings"
@ -38,6 +39,10 @@ func LoadConfig() error {
func GetWechat() *string { func GetWechat() *string {
wechat := getEnv("wechat") wechat := getEnv("wechat")
if wechat != nil {
return wechat
}
if config == nil { if config == nil {
return nil return nil
} }
@ -49,6 +54,10 @@ func GetWechat() *string {
func GetWechatKeyword() *string { func GetWechatKeyword() *string {
keyword := getEnv("wechat_keyword") keyword := getEnv("wechat_keyword")
if keyword != nil {
return keyword
}
if config == nil { if config == nil {
return nil return nil
} }
@ -60,6 +69,10 @@ func GetWechatKeyword() *string {
func GetTelegram() *string { func GetTelegram() *string {
tg := getEnv("telegram") tg := getEnv("telegram")
fmt.Println(tg)
if tg != nil {
return tg
}
if config == nil { if config == nil {
return nil return nil
} }
@ -71,6 +84,10 @@ func GetTelegram() *string {
func GetTelegramKeyword() *string { func GetTelegramKeyword() *string {
tgKeyword := getEnv("tg_keyword") tgKeyword := getEnv("tg_keyword")
if tgKeyword != nil {
return tgKeyword
}
if config == nil { if config == nil {
return nil return nil
} }
@ -82,6 +99,10 @@ func GetTelegramKeyword() *string {
func GetTelegramWhitelist() *string { func GetTelegramWhitelist() *string {
tgWhitelist := getEnv("tg_whitelist") tgWhitelist := getEnv("tg_whitelist")
if tgWhitelist != nil {
return tgWhitelist
}
if config == nil { if config == nil {
return nil return nil
} }
@ -93,6 +114,11 @@ func GetTelegramWhitelist() *string {
func GetOpenAiApiKey() *string { func GetOpenAiApiKey() *string {
apiKey := getEnv("api_key") apiKey := getEnv("api_key")
if apiKey != nil {
return apiKey
}
if config == nil { if config == nil {
return nil return nil
} }
@ -104,11 +130,14 @@ func GetOpenAiApiKey() *string {
func getEnv(key string) *string { func getEnv(key string) *string {
value := os.Getenv(key) value := os.Getenv(key)
if len(value) == 0 { if len(value) == 0 {
value = os.Getenv(strings.ToUpper(key)) value = os.Getenv(strings.ToUpper(key))
} }
if len(value) > 0 {
return &value
}
if config == nil { if config == nil {
return nil return nil
} }