From f392ca7dfd2dfe28f38e46820374702fb2009100 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E8=B6=85=E8=B6=8A?= <993921@qq.com> Date: Sat, 16 Mar 2024 10:38:57 +0800 Subject: [PATCH] wip: debugging --- .gitignore | 5 +++-- config/config.toml | 30 ++++++++++++++++++++++++++++++ main.go | 10 ++++++++++ util/config/config.go | 9 +++++++-- 4 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 config/config.toml diff --git a/.gitignore b/.gitignore index 60bb304..4cfda1d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,8 @@ runtime/ .env dist/ -config.toml +config.*.toml db/geecaptcha.db captcha-bot -dict/dec_* \ No newline at end of file +dict/dec_* +.vscode \ No newline at end of file diff --git a/config/config.toml b/config/config.toml new file mode 100644 index 0000000..57af796 --- /dev/null +++ b/config/config.toml @@ -0,0 +1,30 @@ +#系统设置 +[system] +app_debbug=false +join_hint_after_del_time=60 # 加群验证提示消息多久删除,秒 +captcha_timeout=120 # 验证超时时间,秒 +runtime_path="/runtime" # 缓存目录 + +#telegram 配置 +[telegram] +bot_token="" # 机器人apitoken +api_proxy="" # telegram api代理,仅大陆地区服务器需要 +manage_users=[] # 超级管理员userid数组,以英文逗号分割,例如123,456,789 + +#日志配置 +[log] +max_size=32 +max_age=7 +max_backups=3 + +#消息模板 +[message] +join_hint="欢迎 [%s](%s) 加入 %s\n ⚠️本群已开启新成员验证功能,未通过验证的用户无法发言 \n超时未完成验证会被移除本群! \n⏱本条消息 %d 秒后自动删除\n👇点击下方按钮自助解除禁言" +captcha_image="欢迎您加入[%s]!\n⚠本群已开启新成员验证功能。\n👆为了证明您不是机器人,请发送以上图片验证码内容\n🤖机器人将自动验证您发送的验证码内容是否正确\n⏱本条验证消息有效期[%d]秒" +verification_complete="恭喜您成功通过[🤖人机验证],系统已为您解除禁言限制。\n如若还是无法发言,请重启telegram客户端\n请同时注意群内发言规范,以防永久禁止" +block_hint="\\#封禁预警\n[%s](%s) 请注意,您的消息中含有部分违禁词 \n⚠️您已被系统判断为高风险用户,已被封禁\n系统已向超管发送预警信息,若由超管判定为误杀,会及时将您解除封禁。\n您的违禁词包含:%s" + +#广告阻止 +[adblock] +number_of_forbidden_words=2 # 违禁词判定个数,如果一句话中出现的违禁词为该设置个数,则判断为违禁 +block_time=-1 # 阻止时间,单位:秒。如果为-1,则代表永久封禁 diff --git a/main.go b/main.go index 686d159..3002ce0 100644 --- a/main.go +++ b/main.go @@ -1,9 +1,19 @@ package main import ( + "fmt" + "net/http" + "github.com/assimon/captcha-bot/bootstrap" ) func main() { + go func() { + http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf(w, "OK") + }) + http.ListenAndServe(":8080", nil) + }() + bootstrap.Start() } diff --git a/util/config/config.go b/util/config/config.go index 00dd733..61058c5 100644 --- a/util/config/config.go +++ b/util/config/config.go @@ -1,9 +1,10 @@ package config import ( - "github.com/spf13/viper" "log" "os" + + "github.com/spf13/viper" ) var AppPath string @@ -55,7 +56,11 @@ func InitConfig() { log.Fatal(err) } AppPath = path - viper.SetConfigFile(path + "/config/config.toml") + if os.Getenv("Env") == "dev" { + viper.SetConfigFile(path + "/config/config.dev.toml") + } else { + viper.SetConfigFile(path + "/config/config.toml") + } err = viper.ReadInConfig() if err != nil { log.Fatal("load config file err:", err)