Skip to content

Commit

Permalink
Merge pull request assimon#6 from assimon/dev
Browse files Browse the repository at this point in the history
修复事件监听逻辑,将内存数据结构改为本地sqlite存储
  • Loading branch information
assimon authored Nov 15, 2023
2 parents 82b2006 + 7b9f7a0 commit 3d34516
Show file tree
Hide file tree
Showing 18 changed files with 775 additions and 3,555 deletions.
37 changes: 25 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
FROM debian:bullseye-slim
RUN apt-get update -y \
&& apt-get install -y libsqlite3-dev \
&& apt-get install -y sqlite3 \
&& apt-get install -y libc6 \
&& apt-get install -y libc6-dev \
&& apt-get install -y musl
RUN mkdir -p /app/db
ADD config.toml /app/
ADD captcha-bot /app/
ADD cacert.pem /etc/ssl/certs/
FROM golang:latest as builder

WORKDIR /app
ENTRYPOINT ["./captcha-bot"]

COPY . .

RUN apt-get update && apt-get install -y musl-tools

ENV CGO_ENABLED=1 \
GOOS=linux \
GOARCH=amd64 \
CC=x86_64-linux-musl-gcc \
CXX=x86_64-linux-musl-g++ \
GOPROXY=https://goproxy.cn,direct

RUN go mod download
RUN go mod verify
RUN go build -ldflags '-linkmode external -extldflags "-static"' -o captcha-bot

FROM alpine:latest

COPY --from=builder /app/captcha-bot /work/captcha-bot

WORKDIR /work

ENTRYPOINT ["./captcha-bot"]
10 changes: 3 additions & 7 deletions bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package bootstrap
import (
"github.com/assimon/captcha-bot/telegram"
"github.com/assimon/captcha-bot/util/config"
E "github.com/assimon/captcha-bot/util/error"
"github.com/assimon/captcha-bot/util/log"
"github.com/assimon/captcha-bot/util/orm"
"github.com/assimon/captcha-bot/util/sensitiveword"
Expand All @@ -18,14 +19,9 @@ func Start() {
orm.InitDb()
sensitiveword.InitSensitiveWord()
// 机器人启动
go func() {
defer func() {
if err := recover(); err != nil {
log.Sugar.Error("server bot err:", err)
}
}()
go E.MustPanicErrorFunc(func() {
telegram.BotStart()
}()
})
signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)
<-signalChan
Expand Down
3,281 changes: 0 additions & 3,281 deletions cacert.pem

This file was deleted.

7 changes: 4 additions & 3 deletions example.config.toml → config/example.config.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#系统设置
[system]
app_debbug=false
join_hint_after_del_time=60 # 加群验证提示消息多久删除,秒
captcha_timeout=120 # 验证超时时间,秒
runtime_path="/runtime" # 缓存目录
Expand All @@ -18,9 +19,9 @@ max_backups=3

#消息模板
[message]
join_hint="欢迎 [%s](%s) 加入 %s\n\n⚠️本群已开启新成员验证功能,未通过验证的用户无法发言 \n\n⏱本条消息 %d 秒后自动删除\n\n👇点击下方按钮自助解除禁言"
captcha_image="欢迎您加入[%s]!\n\n⚠本群已开启新成员验证功能。\n\n👆为了证明您不是机器人,请发送以上图片验证码内容\n\n🤖机器人将自动验证您发送的验证码内容是否正确\n\n⏱本条验证消息有效期[%d]秒"
verification_complete="恭喜您成功通过[🤖人机验证],系统已为您解除禁言限制。\n\n如若还是无法发言,请重启telegram客户端"
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"

#广告阻止
Expand Down
15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: '3.8'

services:
captcha-bot:
build:
context: ./
dockerfile: Dockerfile
image: captcha-bot
container_name: captcha-bot
volumes:
- ./db:/work/db
- ./config:/work/config
- ./dict:/work/dict
- ./runtime:/work/runtime
restart: unless-stopped
15 changes: 8 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ go 1.17

require (
github.com/golang-module/carbon/v2 v2.1.8
github.com/importcjj/sensitive v0.0.0-20200106142752-42d1c505be7b
github.com/mojocn/base64Captcha v1.3.5
github.com/robfig/cron v1.2.0
github.com/satori/go.uuid v1.2.0
github.com/spf13/viper v1.12.0
github.com/spf13/viper v1.13.0
go.uber.org/zap v1.17.0
gopkg.in/natefinch/lumberjack.v2 v2.0.0
gopkg.in/telebot.v3 v3.0.0
gopkg.in/telebot.v3 v3.1.4
gorm.io/driver/sqlite v1.3.2
gorm.io/gorm v1.23.5
)
Expand All @@ -18,25 +20,24 @@ require (
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/importcjj/sensitive v0.0.0-20200106142752-42d1c505be7b // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/mattn/go-sqlite3 v1.14.13 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
github.com/spf13/afero v1.8.2 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.3.0 // indirect
github.com/subosito/gotenv v1.4.1 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
golang.org/x/image v0.0.0-20190802002840-cff245a6509b // indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/ini.v1 v1.66.4 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 3d34516

Please sign in to comment.