feat: support kick
This commit is contained in:
46
conf/env.go
46
conf/env.go
@@ -1,54 +1,28 @@
|
||||
package conf
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/ilyakaznacheev/cleanenv"
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type botSettings struct {
|
||||
HTTPProxy string
|
||||
BotToken string
|
||||
MCServer string
|
||||
MCBotName string
|
||||
GroupID int64
|
||||
TGBotApi string
|
||||
HTTPProxy string `env:"HTTP_PROXY"`
|
||||
BotToken string `env:"BOT_TOKEN"`
|
||||
MCServer string `env:"MC_SERVER"`
|
||||
MCBotName string `env:"MC_BOT_NAME"`
|
||||
GroupID int64 `env:"GROUP_ID"`
|
||||
DBPath string `env:"DB_PATH"`
|
||||
}
|
||||
|
||||
var (
|
||||
botSettingsInstance *botSettings
|
||||
botSettingsInstance botSettings
|
||||
)
|
||||
|
||||
func init() {
|
||||
godotenv.Load()
|
||||
http_proxy := os.Getenv("HTTP_PROXY")
|
||||
bot_token := os.Getenv("BOT_TOKEN")
|
||||
mc_server := os.Getenv("MC_SERVER")
|
||||
mc_bot_name := os.Getenv("MC_BOT_NAME")
|
||||
group_id_str := os.Getenv("GROUP_ID")
|
||||
tg_bot_api := os.Getenv("TG_BOT_API")
|
||||
|
||||
if http_proxy == "" || bot_token == "" || mc_server == "" || mc_bot_name == "" || group_id_str == "" || tg_bot_api == "" {
|
||||
logrus.Panic("请检查环境变量是否设置正确")
|
||||
}
|
||||
|
||||
group_id, err := strconv.ParseInt(group_id_str, 10, 64)
|
||||
if err != nil {
|
||||
logrus.Panic("请检查环境变量是否设置正确")
|
||||
}
|
||||
|
||||
botSettingsInstance = &botSettings{
|
||||
HTTPProxy: http_proxy,
|
||||
BotToken: bot_token,
|
||||
MCServer: mc_server,
|
||||
MCBotName: mc_bot_name,
|
||||
GroupID: group_id,
|
||||
TGBotApi: tg_bot_api,
|
||||
}
|
||||
cleanenv.ReadEnv(&botSettingsInstance)
|
||||
}
|
||||
|
||||
func GetBotSettings() *botSettings {
|
||||
return botSettingsInstance
|
||||
return &botSettingsInstance
|
||||
}
|
||||
|
Reference in New Issue
Block a user