commit
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -4,4 +4,5 @@ laniakea/
|
|||||||
config.json
|
config.json
|
||||||
.env.production
|
.env.production
|
||||||
.env.ai
|
.env.ai
|
||||||
|
.env.ban
|
||||||
*.log
|
*.log
|
||||||
@@ -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 BUILD_TIME
|
||||||
ARG GIT_COMMIT
|
ARG GIT_COMMIT
|
||||||
WORKDIR /usr/src/ymgb
|
WORKDIR /usr/src/ymgb
|
||||||
COPY go.mod go.sum ./
|
COPY go.mod go.sum ./
|
||||||
#COPY ./laniakea ./laniakea
|
#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 ./database ./database
|
||||||
COPY ./plugins ./plugins
|
COPY ./plugins ./plugins
|
||||||
COPY ./utils ./utils
|
COPY ./utils ./utils
|
||||||
|
|||||||
4
Makefile
4
Makefile
@@ -4,6 +4,6 @@ export BUILD_TIME := $(shell date "+%H:%M:%S %d.%m.%Y")
|
|||||||
build:
|
build:
|
||||||
@echo "Building commit $(GIT_COMMIT)"
|
@echo "Building commit $(GIT_COMMIT)"
|
||||||
@echo "Build time $(BUILD_TIME)"
|
@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 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
|
docker push git.nix13.pw/scuroneko/yaemikobot:dev
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ services:
|
|||||||
- ./scripts/postgres:/docker-entrypoint-initdb.d
|
- ./scripts/postgres:/docker-entrypoint-initdb.d
|
||||||
- postgres_data:/var/lib/postgresql/data
|
- postgres_data:/var/lib/postgresql/data
|
||||||
mongo:
|
mongo:
|
||||||
image: mongo:8.2.5-noble
|
image: mongo:8-noble
|
||||||
networks:
|
networks:
|
||||||
- bot
|
- bot
|
||||||
ports:
|
ports:
|
||||||
@@ -31,8 +31,8 @@ services:
|
|||||||
healthcheck:
|
healthcheck:
|
||||||
test: [ "CMD", "mongosh", "--quiet", "admin", "--eval", "quit(db.runCommand({ ping: 1 }).ok ? 0 : 2)" ]
|
test: [ "CMD", "mongosh", "--quiet", "admin", "--eval", "quit(db.runCommand({ ping: 1 }).ok ? 0 : 2)" ]
|
||||||
interval: 10s
|
interval: 10s
|
||||||
timeout: 10s
|
|
||||||
retries: 5
|
retries: 5
|
||||||
|
timeout: 10s
|
||||||
start_period: 10s
|
start_period: 10s
|
||||||
volumes:
|
volumes:
|
||||||
- ./scripts/mongo:/docker-entrypoint-initdb.d
|
- ./scripts/mongo:/docker-entrypoint-initdb.d
|
||||||
@@ -58,4 +58,4 @@ networks:
|
|||||||
volumes:
|
volumes:
|
||||||
postgres_data:
|
postgres_data:
|
||||||
mongo_data:
|
mongo_data:
|
||||||
redis_data:
|
redis_data:
|
||||||
|
|||||||
10
go.mod
10
go.mod
@@ -3,8 +3,8 @@ module ymgb
|
|||||||
go 1.26.0
|
go 1.26.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.nix13.pw/scuroneko/extypes v1.2.0
|
git.nix13.pw/scuroneko/extypes v1.2.1
|
||||||
git.nix13.pw/scuroneko/laniakea v0.8.0-beta.3
|
git.nix13.pw/scuroneko/laniakea v1.0.0-beta.3
|
||||||
git.nix13.pw/scuroneko/slog v1.0.2
|
git.nix13.pw/scuroneko/slog v1.0.2
|
||||||
github.com/google/uuid v1.6.0
|
github.com/google/uuid v1.6.0
|
||||||
github.com/joho/godotenv v1.5.1
|
github.com/joho/godotenv v1.5.1
|
||||||
@@ -15,11 +15,12 @@ require (
|
|||||||
go.mongodb.org/mongo-driver/v2 v2.5.0
|
go.mongodb.org/mongo-driver/v2 v2.5.0
|
||||||
)
|
)
|
||||||
|
|
||||||
//replace git.nix13.pw/scuroneko/laniakea v0.7.0 => ./laniakea
|
//replace git.nix13.pw/scuroneko/laniakea v1.0.0-beta.2 => ./laniakea
|
||||||
//replace git.nix13.pw/scuroneko/extypes v1.2.0 => ../go-extypes
|
//replace git.nix13.pw/scuroneko/extypes v1.2.1 => ../go-extypes
|
||||||
//replace git.nix13.pw/scuroneko/slog v1.0.2 => ../slog
|
//replace git.nix13.pw/scuroneko/slog v1.0.2 => ../slog
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/alitto/pond/v2 v2.6.2 // indirect
|
||||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||||
github.com/fatih/color v1.18.0 // 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/sync v0.19.0 // indirect
|
||||||
golang.org/x/sys v0.41.0 // indirect
|
golang.org/x/sys v0.41.0 // indirect
|
||||||
golang.org/x/text v0.34.0 // indirect
|
golang.org/x/text v0.34.0 // indirect
|
||||||
|
golang.org/x/time v0.14.0 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
12
go.sum
12
go.sum
@@ -1,11 +1,13 @@
|
|||||||
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
||||||
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
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.1 h1:IYrOjnWKL2EAuJYtYNa+luB1vBe6paE8VY/YD+5/RpQ=
|
||||||
git.nix13.pw/scuroneko/extypes v1.2.0/go.mod h1:uZVs8Yo3RrYAG9dMad6qR6lsYY67t+459D9c65QAYAw=
|
git.nix13.pw/scuroneko/extypes v1.2.1/go.mod h1:uZVs8Yo3RrYAG9dMad6qR6lsYY67t+459D9c65QAYAw=
|
||||||
git.nix13.pw/scuroneko/laniakea v0.8.0-beta.3 h1:ZXW6TEKmhrqSLHxtLX6JDZeUaeuO5R6qYMhNf01G0Ec=
|
git.nix13.pw/scuroneko/laniakea v1.0.0-beta.3 h1:FtEpeJ6Hi8/RGyT3m7Ysf2AIkwVLflc75HMSQzxPvnc=
|
||||||
git.nix13.pw/scuroneko/laniakea v0.8.0-beta.3/go.mod h1:oYJ4Bp+AsbNBP4clPBJ2ODnJ8oSTihBbi5XaTJa0hMc=
|
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 h1:vZyUROygxC2d5FJHUQM/30xFEHY1JT/aweDZXA4rm2g=
|
||||||
git.nix13.pw/scuroneko/slog v1.0.2/go.mod h1:3Qm2wzkR5KjwOponMfG7TcGSDjmYaFqRAmLvSPTuWJI=
|
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 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
|
||||||
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
|
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
|
||||||
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
|
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.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
|
||||||
golang.org/x/text v0.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk=
|
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/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-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.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||||
|
|||||||
3
main.go
3
main.go
@@ -24,7 +24,7 @@ func main() {
|
|||||||
Mongo: database.MongoClient,
|
Mongo: database.MongoClient,
|
||||||
Redis: database.RedisClient,
|
Redis: database.RedisClient,
|
||||||
})
|
})
|
||||||
bot.AddDatabaseLogger(plugins.DatabaseLogger)
|
bot.AddDatabaseLoggerWriter(plugins.DatabaseLogger)
|
||||||
bot.AddMiddleware(plugins.InitLogMiddleware())
|
bot.AddMiddleware(plugins.InitLogMiddleware())
|
||||||
|
|
||||||
bot.AddPlugins(
|
bot.AddPlugins(
|
||||||
@@ -36,6 +36,7 @@ func main() {
|
|||||||
plugins.RegisterRP(),
|
plugins.RegisterRP(),
|
||||||
plugins.RegisterAi(),
|
plugins.RegisterAi(),
|
||||||
plugins.RegisterFun(),
|
plugins.RegisterFun(),
|
||||||
|
plugins.RegisterProxy(),
|
||||||
)
|
)
|
||||||
|
|
||||||
//plugins.RegisterRelations(bot)
|
//plugins.RegisterRelations(bot)
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ func RegisterAdmin() *laniakea.Plugin[database.Context] {
|
|||||||
p := laniakea.NewPlugin[database.Context]("Admin")
|
p := laniakea.NewPlugin[database.Context]("Admin")
|
||||||
p.AddCommand(laniakea.NewCommand(uploadPhoto, "uploadPhoto").SkipCommandAutoGen())
|
p.AddCommand(laniakea.NewCommand(uploadPhoto, "uploadPhoto").SkipCommandAutoGen())
|
||||||
p.AddCommand(laniakea.NewCommand(emojiId, "emojiId").SkipCommandAutoGen())
|
p.AddCommand(laniakea.NewCommand(emojiId, "emojiId").SkipCommandAutoGen())
|
||||||
p.AddCommand(laniakea.NewCommand(getProxy, "proxy").SkipCommandAutoGen())
|
|
||||||
p.AddCommand(laniakea.NewCommand(execSql, "sql").SkipCommandAutoGen())
|
p.AddCommand(laniakea.NewCommand(execSql, "sql").SkipCommandAutoGen())
|
||||||
|
|
||||||
p.AddMiddleware(AdminMiddleware())
|
p.AddMiddleware(AdminMiddleware())
|
||||||
@@ -62,14 +61,7 @@ func execSql(ctx *laniakea.MsgContext, db *database.Context) {
|
|||||||
}
|
}
|
||||||
ctx.Answerf("`%s`", data)
|
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) {
|
func emojiId(ctx *laniakea.MsgContext, _ *database.Context) {
|
||||||
var id string
|
var id string
|
||||||
for _, e := range ctx.Msg.Entities {
|
for _, e := range ctx.Msg.Entities {
|
||||||
|
|||||||
34
plugins/ban.go
Normal file
34
plugins/ban.go
Normal file
@@ -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)
|
||||||
|
}
|
||||||
@@ -453,7 +453,7 @@ func newChatStage2(ctx *laniakea.MsgContext, db *database.Context) {
|
|||||||
//if err != nil {
|
//if err != nil {
|
||||||
// ctx.Error(err)
|
// ctx.Error(err)
|
||||||
//}
|
//}
|
||||||
//ctx.AnswerCbQueryText(fmt.Sprintf("Ты выбрал сеттинг %s", setting.Name))
|
//ctx.AnswerCbQueryText(fmt.Sprintf("Ты выбрал сеттинг %s", setting.name))
|
||||||
ctx.AnswerCbQuery()
|
ctx.AnswerCbQuery()
|
||||||
}
|
}
|
||||||
func newChat(ctx *laniakea.MsgContext, db *database.Context) {
|
func newChat(ctx *laniakea.MsgContext, db *database.Context) {
|
||||||
|
|||||||
15
scripts/postgres/08-ban.sql
Normal file
15
scripts/postgres/08-ban.sql
Normal file
@@ -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);
|
||||||
75
utils/hysteria2.go
Normal file
75
utils/hysteria2.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user