laniakea v1.0.0 rc1

This commit is contained in:
2026-03-17 16:54:18 +03:00
parent 9a34d05572
commit 7943c860ab
12 changed files with 84 additions and 68 deletions

13
.dockerignore Normal file
View File

@@ -0,0 +1,13 @@
.git
.gitignore
.idea
.env
.env.*
*.log
logs/
Dockerfile
README.md
Makefile
build.bat
docker-compose.yml
db.docker-compose.yml

View File

@@ -1,25 +1,28 @@
# syntax=docker/dockerfile:1.7
FROM golang:1.26-alpine3.23 AS builder FROM golang:1.26-alpine3.23 AS builder
ARG BUILD_TIME ARG BUILD_TIME=unknown
ARG GIT_COMMIT ARG GIT_COMMIT=unknown
ARG TARGETOS
ARG TARGETARCH
WORKDIR /usr/src/ymgb WORKDIR /usr/src/ymgb
COPY go.mod go.sum ./ COPY go.mod go.sum ./
#COPY ./laniakea ./laniakea RUN --mount=type=cache,target=/go/pkg/mod,sharing=locked \
RUN --mount=type=cache,target=/go/pkg/mod go mod download -x go mod download
COPY ./database ./database COPY . .
COPY ./plugins ./plugins RUN --mount=type=cache,target=/root/.cache/go-build,sharing=locked \
COPY ./utils ./utils --mount=type=cache,target=/go/pkg/mod,sharing=locked \
COPY ./openai ./openai CGO_ENABLED=0 GOOS="${TARGETOS:-linux}" GOARCH="${TARGETARCH:-amd64}" \
COPY ./main.go ./ go build -trimpath \
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \
CGO_ENABLED=0 go build -trimpath \
-ldflags="-s -w -X 'ymgb/utils.BuildTime=$BUILD_TIME' -X 'ymgb/utils.GitCommit=$GIT_COMMIT'" \ -ldflags="-s -w -X 'ymgb/utils.BuildTime=$BUILD_TIME' -X 'ymgb/utils.GitCommit=$GIT_COMMIT'" \
-v -o /usr/local/bin/ymgb ./ -o /out/ymgb ./
FROM alpine:3.23 AS runner FROM alpine:3.23 AS runner
RUN apk add --no-cache ca-certificates tzdata \
&& addgroup -S ymgb \
&& adduser -S -D -H -G ymgb ymgb
WORKDIR /app WORKDIR /app
ENV TZ=Europe/Moscow ENV TZ=Europe/Moscow
ENV GOMEMLIMIT=256MiB COPY --from=builder --chown=ymgb:ymgb /out/ymgb /app/ymgb
COPY --from=builder /usr/local/bin/ymgb /app/ymgb USER ymgb:ymgb
CMD ["/app/ymgb"] ENTRYPOINT ["/app/ymgb"]
USER nobody

View File

@@ -10,6 +10,6 @@
While development, if needed to change core code, clone dev branch [Laniakea](https://git.nix13.pw/ScuroNeko/Laniakea) inside root folder as `laniakea`. While development, if needed to change core code, clone dev branch [Laniakea](https://git.nix13.pw/ScuroNeko/Laniakea) inside root folder as `laniakea`.
Uncomment `replace git.nix13.pw/scuroneko/laniakea v{VERSION} => ./laniakea`. Uncomment `replace git.nix13.pw/scuroneko/laniakea v{VERSION} => ./laniakea`.
You can build docker with custom core. Add `COPY ./laniakea ./laniakea` after `COPY go.mod go.sum ./`. Docker build now copies the whole project context except files excluded by `.dockerignore`, so a local `./laniakea` folder is picked up automatically when the `replace` directive is enabled.
To build with release core, remove rename from `go.mod` To build with release core, remove rename from `go.mod`

View File

@@ -48,7 +48,7 @@ func GetConsoleLogs(db *database.Context) ([]ConsoleLogEntry, error) {
type MessageLogEntry struct { type MessageLogEntry struct {
MessageID int `bson:"messageId" json:"message_id"` MessageID int `bson:"messageId" json:"message_id"`
SenderID int `bson:"senderId" json:"sender_id"` SenderID int64 `bson:"senderId" json:"sender_id"`
ChatID int64 `bson:"chatId" json:"chat_id"` ChatID int64 `bson:"chatId" json:"chat_id"`
Text string `bson:"text" json:"text"` Text string `bson:"text" json:"text"`
TimeStamp int64 `bson:"timestamp" json:"timestamp"` TimeStamp int64 `bson:"timestamp" json:"timestamp"`

View File

@@ -13,7 +13,7 @@ import (
) )
type User struct { type User struct {
ID int ID int64
Balance decimal.Decimal Balance decimal.Decimal
Name string Name string
GroupID int `db:"group_id"` GroupID int `db:"group_id"`
@@ -60,7 +60,7 @@ func NewUserRepository(db *database.Context) UserRepository {
return newUserRepository(db.Postgres) return newUserRepository(db.Postgres)
} }
func (rep UserRepository) GetOrCreate(tgId int, name string) (*User, error) { func (rep UserRepository) GetOrCreate(tgId int64, name string) (*User, error) {
user, err := rep.GetById(tgId) user, err := rep.GetById(tgId)
if errors.Is(err, sql.ErrNoRows) { if errors.Is(err, sql.ErrNoRows) {
user, err = rep.Create(tgId, name) user, err = rep.Create(tgId, name)
@@ -68,13 +68,13 @@ func (rep UserRepository) GetOrCreate(tgId int, name string) (*User, error) {
return user, err return user, err
} }
func (rep UserRepository) Create(id int, name string) (*User, error) { func (rep UserRepository) Create(id int64, name string) (*User, error) {
user := new(User) user := new(User)
err := rep.db.Get(user, "INSERT INTO users (id, name) VALUES ($1, $2) RETURNING *;", id, name) err := rep.db.Get(user, "INSERT INTO users (id, name) VALUES ($1, $2) RETURNING *;", id, name)
return user, err return user, err
} }
func (rep UserRepository) GetById(telegramId int) (*User, error) { func (rep UserRepository) GetById(telegramId int64) (*User, error) {
user := new(User) user := new(User)
err := rep.db.Get(user, "SELECT * FROM users WHERE id=$1;", telegramId) err := rep.db.Get(user, "SELECT * FROM users WHERE id=$1;", telegramId)
if err != nil { if err != nil {
@@ -125,7 +125,7 @@ func (rep UserRepository) GetJoins(user *User) (*User, error) {
user.Miner = &miner user.Miner = &miner
} }
if user.PairID.Valid { if user.PairID.Valid {
pair, err := rep.GetById(int(user.PairID.Int64)) pair, err := rep.GetById(user.PairID.Int64)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -9,7 +9,7 @@ import (
) )
type Waifu struct { type Waifu struct {
ID int ID int64
OwnerID sql.NullInt64 `db:"owner_id"` OwnerID sql.NullInt64 `db:"owner_id"`
Name string Name string
Rarity int Rarity int
@@ -51,7 +51,7 @@ func (rep *WaifuRepository) GetAll() ([]*Waifu, error) {
return waifus, err return waifus, err
} }
func (rep *WaifuRepository) GetByUserId(userId int) ([]*Waifu, error) { func (rep *WaifuRepository) GetByUserId(userId int64) ([]*Waifu, error) {
waifus, err := sqlx.List[*Waifu](rep.db, "SELECT waifus.* FROM waifus WHERE owner_id=$1;", userId) waifus, err := sqlx.List[*Waifu](rep.db, "SELECT waifus.* FROM waifus WHERE owner_id=$1;", userId)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -69,7 +69,7 @@ func (rep *WaifuRepository) GetByUserId(userId int) ([]*Waifu, error) {
return waifus, nil return waifus, nil
} }
func (rep *WaifuRepository) GetCountByUserId(userId int) (int64, error) { func (rep *WaifuRepository) GetCountByUserId(userId int64) (int64, error) {
var count int64 = 0 var count int64 = 0
err := rep.db.QueryRow("SELECT COUNT(*) FROM waifus WHERE owner_id=$1;", userId).Scan(&count) err := rep.db.QueryRow("SELECT COUNT(*) FROM waifus WHERE owner_id=$1;", userId).Scan(&count)
return count, err return count, err
@@ -91,7 +91,7 @@ func (rep *WaifuRepository) GetFreeByRarity(rarity int) ([]Waifu, error) {
return waifus, err return waifus, err
} }
func (rep *WaifuRepository) GetById(id int) (*Waifu, error) { func (rep *WaifuRepository) GetById(id int64) (*Waifu, error) {
waifu := new(Waifu) waifu := new(Waifu)
err := rep.db.Get(waifu, "SELECT * FROM waifus WHERE id=$1;", id) err := rep.db.Get(waifu, "SELECT * FROM waifus WHERE id=$1;", id)
if err != nil { if err != nil {

View File

@@ -23,8 +23,8 @@ type RPRepository struct {
type RPChat struct { type RPChat struct {
ID uuid.UUID ID uuid.UUID
UserID int UserID int64
WaifuID int WaifuID int64
Prompt string Prompt string
Counter int Counter int
ChatTokens int64 ChatTokens int64
@@ -39,25 +39,25 @@ func NewRPRepository(db *database.Context) RPRepository {
return RPRepository{db.Redis, db} return RPRepository{db.Redis, db}
} }
func (rep RPRepository) SetSelectedWaifu(userId, waifuId int) error { func (rep RPRepository) SetSelectedWaifu(userId, waifuId int64) error {
key := fmt.Sprintf("ai.chats.rp.%d", userId) key := fmt.Sprintf("ai.chats.rp.%d", userId)
return rep.client.Set(ctx, key, waifuId, 0).Err() return rep.client.Set(ctx, key, waifuId, 0).Err()
} }
func (rep RPRepository) GetSelectedWaifu(userId int) int { func (rep RPRepository) GetSelectedWaifu(userId int64) int64 {
key := fmt.Sprintf("ai.chats.rp.%d", userId) key := fmt.Sprintf("ai.chats.rp.%d", userId)
res := rep.client.Get(ctx, key) res := rep.client.Get(ctx, key)
if res.Err() != nil { if res.Err() != nil {
return 0 return 0
} }
i, _ := res.Int() i, _ := res.Int()
return i return int64(i)
} }
func (rep RPRepository) SetChatId(userId, waifuId int, chatId string) error { func (rep RPRepository) SetChatId(userId, waifuId int64, chatId string) error {
key := fmt.Sprintf("ai.chats.rp.%d.%d.chat", userId, waifuId) key := fmt.Sprintf("ai.chats.rp.%d.%d.chat", userId, waifuId)
return rep.client.Set(context.Background(), key, chatId, 0).Err() return rep.client.Set(context.Background(), key, chatId, 0).Err()
} }
func (rep RPRepository) GetChatId(userId, waifuId int) string { func (rep RPRepository) GetChatId(userId, waifuId int64) string {
key := fmt.Sprintf("ai.chats.rp.%d.%d.chat", userId, waifuId) key := fmt.Sprintf("ai.chats.rp.%d.%d.chat", userId, waifuId)
res := rep.client.Get(ctx, key) res := rep.client.Get(ctx, key)
if res.Err() != nil { if res.Err() != nil {
@@ -65,7 +65,7 @@ func (rep RPRepository) GetChatId(userId, waifuId int) string {
} }
return res.Val() return res.Val()
} }
func (rep RPRepository) GetOrCreateChatId(userId, waifuId int) (string, error) { func (rep RPRepository) GetOrCreateChatId(userId, waifuId int64) (string, error) {
chatId := rep.GetChatId(userId, waifuId) chatId := rep.GetChatId(userId, waifuId)
if chatId == "" { if chatId == "" {
chatId = uuid.New().String() chatId = uuid.New().String()
@@ -73,7 +73,7 @@ func (rep RPRepository) GetOrCreateChatId(userId, waifuId int) (string, error) {
err := rep.SetChatId(userId, waifuId, chatId) err := rep.SetChatId(userId, waifuId, chatId)
return chatId, err return chatId, err
} }
func (rep RPRepository) GetChat(userId int) (RPChat, error) { func (rep RPRepository) GetChat(userId int64) (RPChat, error) {
var chat RPChat var chat RPChat
waifuId := rep.GetSelectedWaifu(userId) waifuId := rep.GetSelectedWaifu(userId)
if waifuId == 0 { if waifuId == 0 {
@@ -133,7 +133,7 @@ func (rep RPRepository) SaveChat(chat RPChat) error {
if err = rep.SetCounter(userId, waifuId, chat.Counter); err != nil { if err = rep.SetCounter(userId, waifuId, chat.Counter); err != nil {
return err return err
} }
if err = rep.SetChatTokens(userId, waifuId, int(chat.ChatTokens)); err != nil { if err = rep.SetChatTokens(userId, waifuId, chat.ChatTokens); err != nil {
return err return err
} }
@@ -161,11 +161,11 @@ func (rep RPRepository) SaveChat(chat RPChat) error {
return nil return nil
} }
func (rep RPRepository) SetChatPrompt(userId, waifuId int, prompt string) error { func (rep RPRepository) SetChatPrompt(userId, waifuId int64, prompt string) error {
key := fmt.Sprintf("ai.chats.rp.%d.%d.prompt", userId, waifuId) key := fmt.Sprintf("ai.chats.rp.%d.%d.prompt", userId, waifuId)
return rep.client.Set(context.Background(), key, prompt, 0).Err() return rep.client.Set(context.Background(), key, prompt, 0).Err()
} }
func (rep RPRepository) GetChatPrompt(userId, waifuId int) string { func (rep RPRepository) GetChatPrompt(userId, waifuId int64) string {
key := fmt.Sprintf("ai.chats.rp.%d.%d.prompt", userId, waifuId) key := fmt.Sprintf("ai.chats.rp.%d.%d.prompt", userId, waifuId)
res := rep.client.Get(ctx, key) res := rep.client.Get(ctx, key)
if res.Err() != nil { if res.Err() != nil {
@@ -174,11 +174,11 @@ func (rep RPRepository) GetChatPrompt(userId, waifuId int) string {
return res.Val() return res.Val()
} }
func (rep RPRepository) SetCounter(userId, waifuId, counter int) error { func (rep RPRepository) SetCounter(userId, waifuId int64, counter int) error {
key := fmt.Sprintf("ai.chats.rp.%d.%d.counter", userId, waifuId) key := fmt.Sprintf("ai.chats.rp.%d.%d.counter", userId, waifuId)
return rep.client.Set(ctx, key, counter, 0).Err() return rep.client.Set(ctx, key, counter, 0).Err()
} }
func (rep RPRepository) GetCounter(userId, waifuId int) int { func (rep RPRepository) GetCounter(userId, waifuId int64) int {
key := fmt.Sprintf("ai.chats.rp.%d.%d.counter", userId, waifuId) key := fmt.Sprintf("ai.chats.rp.%d.%d.counter", userId, waifuId)
res := rep.client.Get(ctx, key) res := rep.client.Get(ctx, key)
if res.Err() != nil { if res.Err() != nil {
@@ -188,25 +188,25 @@ func (rep RPRepository) GetCounter(userId, waifuId int) int {
return i return i
} }
func (rep RPRepository) SetChatTokens(userId, waifuId, tokens int) error { func (rep RPRepository) SetChatTokens(userId, waifuId, tokens int64) error {
key := fmt.Sprintf("ai.chats.rp.%d.%d.tokens", userId, waifuId) key := fmt.Sprintf("ai.chats.rp.%d.%d.tokens", userId, waifuId)
return rep.client.Set(ctx, key, tokens, 0).Err() return rep.client.Set(ctx, key, tokens, 0).Err()
} }
func (rep RPRepository) GetChatTokens(userId, waifuId int) int { func (rep RPRepository) GetChatTokens(userId, waifuId int64) int64 {
key := fmt.Sprintf("ai.chats.rp.%d.%d.tokens", userId, waifuId) key := fmt.Sprintf("ai.chats.rp.%d.%d.tokens", userId, waifuId)
res := rep.client.Get(ctx, key) res := rep.client.Get(ctx, key)
if res.Err() != nil { if res.Err() != nil {
return 0 return 0
} }
i, _ := res.Int() i, _ := res.Int()
return i return int64(i)
} }
func (rep RPRepository) SetChatSettingID(userId, waifuId, settingId int) error { func (rep RPRepository) SetChatSettingID(userId, waifuId int64, settingId int) error {
key := fmt.Sprintf("ai.chats.rp.%d.%d.setting_id", userId, waifuId) key := fmt.Sprintf("ai.chats.rp.%d.%d.setting_id", userId, waifuId)
return rep.client.Set(ctx, key, settingId, 0).Err() return rep.client.Set(ctx, key, settingId, 0).Err()
} }
func (rep RPRepository) GetChatSettingID(userId, waifuId int) int { func (rep RPRepository) GetChatSettingID(userId, waifuId int64) int {
key := fmt.Sprintf("ai.chats.rp.%d.%d.setting_id", userId, waifuId) key := fmt.Sprintf("ai.chats.rp.%d.%d.setting_id", userId, waifuId)
res := rep.client.Get(ctx, key) res := rep.client.Get(ctx, key)
if res.Err() != nil { if res.Err() != nil {
@@ -216,12 +216,12 @@ func (rep RPRepository) GetChatSettingID(userId, waifuId int) int {
return i return i
} }
func (rep RPRepository) SetChatScenariosIDs(userId, waifuId int, scenarioIds []int) error { func (rep RPRepository) SetChatScenariosIDs(userId, waifuId int64, scenarioIds []int) error {
key := fmt.Sprintf("ai.chats.rp.%d.%d.scenario_id", userId, waifuId) key := fmt.Sprintf("ai.chats.rp.%d.%d.scenario_id", userId, waifuId)
ids := strings.Join(utils.Map(scenarioIds, utils.AnyToString), ",") ids := strings.Join(utils.Map(scenarioIds, utils.AnyToString), ",")
return rep.client.Set(ctx, key, ids, 0).Err() return rep.client.Set(ctx, key, ids, 0).Err()
} }
func (rep RPRepository) GetChatScenariosIDs(userId, waifuId int) []int { func (rep RPRepository) GetChatScenariosIDs(userId, waifuId int64) []int {
key := fmt.Sprintf("ai.chats.rp.%d.%d.scenario_id", userId, waifuId) key := fmt.Sprintf("ai.chats.rp.%d.%d.scenario_id", userId, waifuId)
res := rep.client.Get(ctx, key) res := rep.client.Get(ctx, key)
if res.Err() != nil { if res.Err() != nil {

8
go.mod
View File

@@ -3,9 +3,9 @@ module ymgb
go 1.26.1 go 1.26.1
require ( require (
git.nix13.pw/scuroneko/extypes v1.2.1 git.nix13.pw/scuroneko/extypes v1.2.2
git.nix13.pw/scuroneko/laniakea v1.0.0-beta.21 git.nix13.pw/scuroneko/laniakea v1.0.0-rc.1
git.nix13.pw/scuroneko/slog v1.0.2 git.nix13.pw/scuroneko/slog v1.1.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
github.com/lib/pq v1.11.2 github.com/lib/pq v1.11.2
@@ -15,7 +15,7 @@ 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 v1.0.0-beta.21 => ./laniakea //replace git.nix13.pw/scuroneko/laniakea v1.0.0-rc.1 => ./laniakea
//replace git.nix13.pw/scuroneko/extypes v1.2.1 => ../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

12
go.sum
View File

@@ -1,11 +1,11 @@
filippo.io/edwards25519 v1.1.1 h1:YpjwWWlNmGIDyXOn8zLzqiD+9TyIlPhGFG96P39uBpw= filippo.io/edwards25519 v1.1.1 h1:YpjwWWlNmGIDyXOn8zLzqiD+9TyIlPhGFG96P39uBpw=
filippo.io/edwards25519 v1.1.1/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= filippo.io/edwards25519 v1.1.1/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
git.nix13.pw/scuroneko/extypes v1.2.1 h1:IYrOjnWKL2EAuJYtYNa+luB1vBe6paE8VY/YD+5/RpQ= git.nix13.pw/scuroneko/extypes v1.2.2 h1:N54c1ejrPs1yfIkvYuwqI7B1+8S9mDv2GqQA6sct4dk=
git.nix13.pw/scuroneko/extypes v1.2.1/go.mod h1:uZVs8Yo3RrYAG9dMad6qR6lsYY67t+459D9c65QAYAw= git.nix13.pw/scuroneko/extypes v1.2.2/go.mod h1:b4XYk1OW1dVSiE2MT/OMuX/K/UItf1swytX6eroVYnk=
git.nix13.pw/scuroneko/laniakea v1.0.0-beta.21 h1:bit6fm6xtwoDh3BTjKduzyg++4BLiiQ392NmxnSr5lI= git.nix13.pw/scuroneko/laniakea v1.0.0-rc.1 h1:zh4Mrp9qEX/9p/NGMUXzaWj4G6koTQMYWJeHJ9fB5sM=
git.nix13.pw/scuroneko/laniakea v1.0.0-beta.21/go.mod h1:M8jwm195hzAl9bj9Bkl95WfHmWvuBX6micsdtOs/gmE= git.nix13.pw/scuroneko/laniakea v1.0.0-rc.1/go.mod h1:gBo6l+CqxhcL6oI4YgAK7Z5PkwkZRRzhVrQWji2WAAg=
git.nix13.pw/scuroneko/slog v1.0.2 h1:vZyUROygxC2d5FJHUQM/30xFEHY1JT/aweDZXA4rm2g= git.nix13.pw/scuroneko/slog v1.1.2 h1:pl7tV5FN25Yso7sLYoOgBXi9+jLo5BDJHWmHlNPjpY0=
git.nix13.pw/scuroneko/slog v1.0.2/go.mod h1:3Qm2wzkR5KjwOponMfG7TcGSDjmYaFqRAmLvSPTuWJI= git.nix13.pw/scuroneko/slog v1.1.2/go.mod h1:UcfRIHDqpVQHahBGM93awLDK8//AsAvOqBwwbWqMkjM=
github.com/alitto/pond/v2 v2.7.0 h1:c76L+yN916m/DRXjGCeUBHHu92uWnh/g1bwVk4zyyXg= github.com/alitto/pond/v2 v2.7.0 h1:c76L+yN916m/DRXjGCeUBHHu92uWnh/g1bwVk4zyyXg=
github.com/alitto/pond/v2 v2.7.0/go.mod h1:xkjYEgQ05RSpWdfSd1nM3OVv7TBhLdy7rMp3+2Nq+yE= github.com/alitto/pond/v2 v2.7.0/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=

View File

@@ -107,7 +107,7 @@ func uploadPhoto(ctx *laniakea.MsgContext, _ *database.Context) {
return return
} }
filename := filepath.Base(f.FilePath) filename := filepath.Base(f.FilePath)
msg, err := u.UploadPhoto(tgapi.UploadPhotoP{ msg, err := u.SendPhoto(tgapi.UploadPhotoP{
ChatID: ctx.Msg.Chat.ID, ChatID: ctx.Msg.Chat.ID,
Caption: ctx.Msg.Caption, Caption: ctx.Msg.Caption,
}, tgapi.NewUploaderFile(filename, content)) }, tgapi.NewUploaderFile(filename, content))

View File

@@ -189,14 +189,14 @@ func rpWaifuSet(ctx *laniakea.MsgContext, db *database.Context) {
return return
} }
rpRepRed := red.NewRPRepository(db) rpRepRed := red.NewRPRepository(db)
err = rpRepRed.SetSelectedWaifu(ctx.FromID, waifuId) err = rpRepRed.SetSelectedWaifu(ctx.FromID, int64(waifuId))
if err != nil { if err != nil {
ctx.Error(err) ctx.Error(err)
return return
} }
//rpRepPsql := psql.NewRPRepository(db) //rpRepPsql := psql.NewRPRepository(db)
waifuRep := psql.NewWaifuRepository(db) waifuRep := psql.NewWaifuRepository(db)
waifu, err := waifuRep.GetById(waifuId) waifu, err := waifuRep.GetById(int64(waifuId))
if err != nil { if err != nil {
ctx.Error(err) ctx.Error(err)
} }
@@ -756,7 +756,7 @@ func generate(ctx *laniakea.MsgContext, db *database.Context) {
} }
tokens := redisRpRep.GetChatTokens(ctx.FromID, waifuId) tokens := redisRpRep.GetChatTokens(ctx.FromID, waifuId)
tokens += len(userMessage) + len(answerContent) tokens += int64(len(userMessage) + len(answerContent))
err = redisRpRep.SetChatTokens(ctx.FromID, waifuId, tokens) err = redisRpRep.SetChatTokens(ctx.FromID, waifuId, tokens)
if err != nil { if err != nil {
ctx.Error(err) ctx.Error(err)
@@ -780,7 +780,7 @@ func generate(ctx *laniakea.MsgContext, db *database.Context) {
m.Delete() m.Delete()
} }
case "tokens": case "tokens":
if tokens >= rpUser.CompressLimit*1000 { if tokens >= int64(rpUser.CompressLimit*1000) {
m = ctx.Answer("Запущено сжатие чата…") m = ctx.Answer("Запущено сжатие чата…")
_compress(ctx, db) _compress(ctx, db)
m.Delete() m.Delete()
@@ -966,7 +966,7 @@ func _compress(ctx *laniakea.MsgContext, db *database.Context) {
if err != nil { if err != nil {
ctx.Error(err) ctx.Error(err)
} }
err = redisRpRep.SetChatTokens(ctx.FromID, waifuId, tokens) err = redisRpRep.SetChatTokens(ctx.FromID, waifuId, int64(tokens))
if err != nil { if err != nil {
ctx.Error(err) ctx.Error(err)
} }

View File

@@ -118,7 +118,7 @@ func waifuSell(ctx *laniakea.MsgContext, db *database.Context) {
} }
rep := psql.NewWaifuRepository(db) rep := psql.NewWaifuRepository(db)
waifu, err := rep.GetById(waifuId) waifu, err := rep.GetById(int64(waifuId))
if err != nil { if err != nil {
ctx.Error(err) ctx.Error(err)
return return
@@ -164,7 +164,7 @@ func waifuInfo(ctx *laniakea.MsgContext, db *database.Context) {
} }
rep := psql.NewWaifuRepository(db) rep := psql.NewWaifuRepository(db)
waifu, err := rep.GetById(waifuId) waifu, err := rep.GetById(int64(waifuId))
if err != nil { if err != nil {
ctx.Error(err) ctx.Error(err)
return return