From b394c0be68b70e72995b23f84dadb7fe04f83a31 Mon Sep 17 00:00:00 2001 From: ScuroNeko Date: Fri, 27 Feb 2026 15:36:00 +0300 Subject: [PATCH] commit --- .gitignore | 1 + Dockerfile | 4 +- Makefile | 4 +- db.docker-compose.yml | 6 +-- go.mod | 10 +++-- go.sum | 12 ++++-- main.go | 3 +- plugins/admin.go | 10 +---- plugins/ban.go | 34 +++++++++++++++++ plugins/rp.go | 2 +- scripts/postgres/08-ban.sql | 15 ++++++++ utils/hysteria2.go | 75 +++++++++++++++++++++++++++++++++++++ 12 files changed, 150 insertions(+), 26 deletions(-) create mode 100644 plugins/ban.go create mode 100644 scripts/postgres/08-ban.sql create mode 100644 utils/hysteria2.go diff --git a/.gitignore b/.gitignore index 587ef72..53e2872 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ laniakea/ config.json .env.production .env.ai +.env.ban *.log \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 11cea49..d108f54 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,10 @@ -FROM golang:1.26.0-alpine3.23 AS builder +FROM golang:1.26-alpine3.23 AS builder ARG BUILD_TIME ARG GIT_COMMIT WORKDIR /usr/src/ymgb COPY go.mod go.sum ./ #COPY ./laniakea ./laniakea -RUN --mount=type=cache,target=/go/pkg/mod go mod download +RUN --mount=type=cache,target=/go/pkg/mod go mod download -x COPY ./database ./database COPY ./plugins ./plugins COPY ./utils ./utils diff --git a/Makefile b/Makefile index 9f95dcc..ff4e07b 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,6 @@ export BUILD_TIME := $(shell date "+%H:%M:%S %d.%m.%Y") build: @echo "Building commit $(GIT_COMMIT)" @echo "Build time $(BUILD_TIME)" - go mod tidy + go mod tidy -v -x docker build --build-arg GIT_COMMIT --build-arg BUILD_TIME -t git.nix13.pw/scuroneko/yaemikobot:dev -f ./Dockerfile . - docker push git.nix13.pw/scuroneko/yaemikobot:dev \ No newline at end of file + docker push git.nix13.pw/scuroneko/yaemikobot:dev diff --git a/db.docker-compose.yml b/db.docker-compose.yml index 88666af..c8ff314 100644 --- a/db.docker-compose.yml +++ b/db.docker-compose.yml @@ -19,7 +19,7 @@ services: - ./scripts/postgres:/docker-entrypoint-initdb.d - postgres_data:/var/lib/postgresql/data mongo: - image: mongo:8.2.5-noble + image: mongo:8-noble networks: - bot ports: @@ -31,8 +31,8 @@ services: healthcheck: test: [ "CMD", "mongosh", "--quiet", "admin", "--eval", "quit(db.runCommand({ ping: 1 }).ok ? 0 : 2)" ] interval: 10s - timeout: 10s retries: 5 + timeout: 10s start_period: 10s volumes: - ./scripts/mongo:/docker-entrypoint-initdb.d @@ -58,4 +58,4 @@ networks: volumes: postgres_data: mongo_data: - redis_data: \ No newline at end of file + redis_data: diff --git a/go.mod b/go.mod index f9440a9..66854f9 100644 --- a/go.mod +++ b/go.mod @@ -3,8 +3,8 @@ module ymgb go 1.26.0 require ( - git.nix13.pw/scuroneko/extypes v1.2.0 - git.nix13.pw/scuroneko/laniakea v0.8.0-beta.3 + git.nix13.pw/scuroneko/extypes v1.2.1 + git.nix13.pw/scuroneko/laniakea v1.0.0-beta.3 git.nix13.pw/scuroneko/slog v1.0.2 github.com/google/uuid v1.6.0 github.com/joho/godotenv v1.5.1 @@ -15,11 +15,12 @@ require ( go.mongodb.org/mongo-driver/v2 v2.5.0 ) -//replace git.nix13.pw/scuroneko/laniakea v0.7.0 => ./laniakea -//replace git.nix13.pw/scuroneko/extypes v1.2.0 => ../go-extypes +//replace git.nix13.pw/scuroneko/laniakea v1.0.0-beta.2 => ./laniakea +//replace git.nix13.pw/scuroneko/extypes v1.2.1 => ../go-extypes //replace git.nix13.pw/scuroneko/slog v1.0.2 => ../slog require ( + github.com/alitto/pond/v2 v2.6.2 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/fatih/color v1.18.0 // indirect @@ -37,4 +38,5 @@ require ( golang.org/x/sync v0.19.0 // indirect golang.org/x/sys v0.41.0 // indirect golang.org/x/text v0.34.0 // indirect + golang.org/x/time v0.14.0 // indirect ) diff --git a/go.sum b/go.sum index 9cd3aa5..99f30a6 100644 --- a/go.sum +++ b/go.sum @@ -1,11 +1,13 @@ filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= -git.nix13.pw/scuroneko/extypes v1.2.0 h1:2n2hD6KsMAted+6MGhAyeWyli2Qzc9G2y+pQNB7C1dM= -git.nix13.pw/scuroneko/extypes v1.2.0/go.mod h1:uZVs8Yo3RrYAG9dMad6qR6lsYY67t+459D9c65QAYAw= -git.nix13.pw/scuroneko/laniakea v0.8.0-beta.3 h1:ZXW6TEKmhrqSLHxtLX6JDZeUaeuO5R6qYMhNf01G0Ec= -git.nix13.pw/scuroneko/laniakea v0.8.0-beta.3/go.mod h1:oYJ4Bp+AsbNBP4clPBJ2ODnJ8oSTihBbi5XaTJa0hMc= +git.nix13.pw/scuroneko/extypes v1.2.1 h1:IYrOjnWKL2EAuJYtYNa+luB1vBe6paE8VY/YD+5/RpQ= +git.nix13.pw/scuroneko/extypes v1.2.1/go.mod h1:uZVs8Yo3RrYAG9dMad6qR6lsYY67t+459D9c65QAYAw= +git.nix13.pw/scuroneko/laniakea v1.0.0-beta.3 h1:FtEpeJ6Hi8/RGyT3m7Ysf2AIkwVLflc75HMSQzxPvnc= +git.nix13.pw/scuroneko/laniakea v1.0.0-beta.3/go.mod h1:DZgCqOazRzoa+f/GSNuKnTB2wIZ1eJD3cGf34Qya31U= git.nix13.pw/scuroneko/slog v1.0.2 h1:vZyUROygxC2d5FJHUQM/30xFEHY1JT/aweDZXA4rm2g= git.nix13.pw/scuroneko/slog v1.0.2/go.mod h1:3Qm2wzkR5KjwOponMfG7TcGSDjmYaFqRAmLvSPTuWJI= +github.com/alitto/pond/v2 v2.6.2 h1:Sphe40g0ILeM1pA2c2K+Th0DGU+pt0A/Kprr+WB24Pw= +github.com/alitto/pond/v2 v2.6.2/go.mod h1:xkjYEgQ05RSpWdfSd1nM3OVv7TBhLdy7rMp3+2Nq+yE= github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs= github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c= github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA= @@ -95,6 +97,8 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/text v0.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk= golang.org/x/text v0.34.0/go.mod h1:homfLqTYRFyVYemLBFl5GgL/DWEiH5wcsQ5gSh1yziA= +golang.org/x/time v0.14.0 h1:MRx4UaLrDotUKUdCIqzPC48t1Y9hANFKIRpNx+Te8PI= +golang.org/x/time v0.14.0/go.mod h1:eL/Oa2bBBK0TkX57Fyni+NgnyQQN4LitPmob2Hjnqw4= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= diff --git a/main.go b/main.go index bddca40..94e4ce7 100644 --- a/main.go +++ b/main.go @@ -24,7 +24,7 @@ func main() { Mongo: database.MongoClient, Redis: database.RedisClient, }) - bot.AddDatabaseLogger(plugins.DatabaseLogger) + bot.AddDatabaseLoggerWriter(plugins.DatabaseLogger) bot.AddMiddleware(plugins.InitLogMiddleware()) bot.AddPlugins( @@ -36,6 +36,7 @@ func main() { plugins.RegisterRP(), plugins.RegisterAi(), plugins.RegisterFun(), + plugins.RegisterProxy(), ) //plugins.RegisterRelations(bot) diff --git a/plugins/admin.go b/plugins/admin.go index 552fb01..1ca20a3 100644 --- a/plugins/admin.go +++ b/plugins/admin.go @@ -17,7 +17,6 @@ func RegisterAdmin() *laniakea.Plugin[database.Context] { p := laniakea.NewPlugin[database.Context]("Admin") p.AddCommand(laniakea.NewCommand(uploadPhoto, "uploadPhoto").SkipCommandAutoGen()) p.AddCommand(laniakea.NewCommand(emojiId, "emojiId").SkipCommandAutoGen()) - p.AddCommand(laniakea.NewCommand(getProxy, "proxy").SkipCommandAutoGen()) p.AddCommand(laniakea.NewCommand(execSql, "sql").SkipCommandAutoGen()) p.AddMiddleware(AdminMiddleware()) @@ -62,14 +61,7 @@ func execSql(ctx *laniakea.MsgContext, db *database.Context) { } ctx.Answerf("`%s`", data) } -func getProxy(ctx *laniakea.MsgContext, _ *database.Context) { - ruProxy := "tg://proxy?port=3128&secret=7qaZyfQN-IQ7ZMwrR_zWnHBvem9uLnJ1&server=185.231.245.25" - fiProxy := "tg://proxy?port=3128&secret=7vmNtw_233xvIRFvImm2PLtvem9uLnJ1&server=46.243.6.125" - kb := laniakea.NewInlineKeyboard(1) - kb.AddUrlButtonStyle("🇷🇺Russia", laniakea.ButtonStylePrimary, ruProxy) - kb.AddUrlButtonStyle("🇫🇮Finland", laniakea.ButtonStylePrimary, fiProxy) - ctx.Keyboard("Доступные прокси", kb) -} + func emojiId(ctx *laniakea.MsgContext, _ *database.Context) { var id string for _, e := range ctx.Msg.Entities { diff --git a/plugins/ban.go b/plugins/ban.go new file mode 100644 index 0000000..5ff56d6 --- /dev/null +++ b/plugins/ban.go @@ -0,0 +1,34 @@ +package plugins + +import ( + "ymgb/database" + "ymgb/utils" + + "git.nix13.pw/scuroneko/laniakea" +) + +func RegisterProxy() *laniakea.Plugin[database.Context] { + p := laniakea.NewPlugin[database.Context]("Proxy") + p.AddCommand(laniakea.NewCommand(getH2Link, "h2link")) + p.AddCommand(laniakea.NewCommand(getProxy, "proxy")) + return p +} + +func getH2Link(ctx *laniakea.MsgContext, db *database.Context) { + api := utils.NewHysteria2API() + url, err := api.GetConnectLink(1, "K1321xt90RUS") + if err != nil { + ctx.Error(err) + return + } + ctx.Answerf("`%s`", url) +} + +func getProxy(ctx *laniakea.MsgContext, _ *database.Context) { + ruProxy := "tg://proxy?port=3128&secret=7qaZyfQN-IQ7ZMwrR_zWnHBvem9uLnJ1&server=185.231.245.25" + fiProxy := "tg://proxy?port=3128&secret=7vmNtw_233xvIRFvImm2PLtvem9uLnJ1&server=46.243.6.125" + kb := laniakea.NewInlineKeyboard(1) + kb.AddUrlButtonStyle("🇷🇺Russia", laniakea.ButtonStylePrimary, ruProxy) + kb.AddUrlButtonStyle("🇫🇮Finland", laniakea.ButtonStylePrimary, fiProxy) + ctx.Keyboard("Доступные прокси", kb) +} diff --git a/plugins/rp.go b/plugins/rp.go index 00bb956..2032288 100644 --- a/plugins/rp.go +++ b/plugins/rp.go @@ -453,7 +453,7 @@ func newChatStage2(ctx *laniakea.MsgContext, db *database.Context) { //if err != nil { // ctx.Error(err) //} - //ctx.AnswerCbQueryText(fmt.Sprintf("Ты выбрал сеттинг %s", setting.Name)) + //ctx.AnswerCbQueryText(fmt.Sprintf("Ты выбрал сеттинг %s", setting.name)) ctx.AnswerCbQuery() } func newChat(ctx *laniakea.MsgContext, db *database.Context) { diff --git a/scripts/postgres/08-ban.sql b/scripts/postgres/08-ban.sql new file mode 100644 index 0000000..05a94e5 --- /dev/null +++ b/scripts/postgres/08-ban.sql @@ -0,0 +1,15 @@ +CREATE TABLE h2_hosts( + id SERIAL PRIMARY KEY, + name TEXT NOT NULL, + url TEXT NOT NULL +); +CREATE UNIQUE INDEX h2_hosts_uindex ON h2_hosts(id); + +CREATE TABLE h2_users ( + id SERIAL PRIMARY KEY, + tg_id INT8 REFERENCES users(id), + username TEXT NOT NULL, + password TEXT NOT NULL +); +CREATE UNIQUE INDEX h2_users_uindex ON h2_users(id); +CREATE INDEX h2_users_index ON h2_users(tg_id, username); \ No newline at end of file diff --git a/utils/hysteria2.go b/utils/hysteria2.go new file mode 100644 index 0000000..b623025 --- /dev/null +++ b/utils/hysteria2.go @@ -0,0 +1,75 @@ +package utils + +import ( + "encoding/json" + "fmt" + "io" + "log" + "net/http" + "os" + "strings" +) + +type Hysteria2Response[T any] struct { + Ok bool `json:"ok"` + Data T `json:"data,omitempty"` + Error string `json:"error,omitempty"` +} + +type Hysteria2API struct { + authUrl string + authToken string + statsUrl string + statsSecret string + client *http.Client +} + +func NewHysteria2API() *Hysteria2API { + auth := os.Getenv("H2AUTH") + authToken := os.Getenv("H2AUTH_TOKEN") + stat := os.Getenv("H2STAT") + statsSecret := os.Getenv("H2STAT_SECRET") + c := &http.Client{} + return &Hysteria2API{auth, authToken, stat, statsSecret, c} +} + +func (a *Hysteria2API) AddUser(username, password string) { + req, err := http.NewRequest("POST", a.authUrl+"/add", strings.NewReader(fmt.Sprintf(`{"username":"%s","password":"%s"}`, username, password))) + if err != nil { + return + } + req.Header.Set("Content-Type", "application/json") + req.Header.Set("Authorization", a.authToken) + resp, err := a.client.Do(req) + if err != nil { + return + } + defer resp.Body.Close() + body, _ := io.ReadAll(resp.Body) + log.Println(string(body)) +} + +func (a *Hysteria2API) GetConnectLink(id int, pass string) (string, error) { + body := strings.NewReader(fmt.Sprintf(`{"id":%d,"pass":"%s"}`, id, pass)) + req, err := http.NewRequest("POST", a.authUrl+"/connect", body) + if err != nil { + return "", err + } + req.Header.Set("Content-Type", "application/json") + resp, err := a.client.Do(req) + if err != nil { + return "", err + } + defer resp.Body.Close() + + data, err := io.ReadAll(resp.Body) + if err != nil { + return "", err + } + response := new(Hysteria2Response[string]) + err = json.Unmarshal(data, response) + if err != nil { + return "", err + } + return response.Data, nil +}