compress wip
This commit is contained in:
@@ -3,6 +3,7 @@ ARG BUILD_TIME
|
||||
ARG GIT_COMMIT
|
||||
WORKDIR /usr/src/kurumi
|
||||
COPY go.mod go.sum ./
|
||||
#COPY ./laniakea ./laniakea
|
||||
RUN --mount=type=cache,target=/go/pkg/mod go mod download
|
||||
COPY ./database ./database
|
||||
COPY ./plugins ./plugins
|
||||
|
||||
@@ -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`.
|
||||
Uncomment `replace git.nix13.pw/scuroneko/laniakea v{VERSION} => ./laniakea`.
|
||||
|
||||
You can build docker with custom core. Add `COPY ./laniakea ./laniakea` after `COPY ./utils ./utils` and before `COPY ./main.go ./`.
|
||||
You can build docker with custom core. Add `COPY ./laniakea ./laniakea` after `COPY go.mod go.sum ./`.
|
||||
|
||||
To build with release core, remove rename from `go.mod`
|
||||
@@ -133,6 +133,61 @@ func (rep *UserRepository) GetById(telegramId int) (*User, error) {
|
||||
return user, err
|
||||
}
|
||||
|
||||
func (rep *UserRepository) GetJoins(user *User) (*User, error) {
|
||||
err := sqlx.Transact(rep.db, func(ctx context.Context, db sqlx.Queryable) error {
|
||||
user.Group = new(Group)
|
||||
err := rep.db.Get(user.Group, "SELECT * FROM groups WHERE id=$1;", user.GroupID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
user.Work = new(Work)
|
||||
err = rep.db.Get(user.Work, "SELECT * FROM works WHERE id=$1;", user.WorkID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
shopRep := NewShopRepository(rep.db)
|
||||
if user.AutoID.Valid {
|
||||
user.Auto, err = shopRep.GetAuto(user.AutoID.Int32)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if user.BusinessID.Valid {
|
||||
user.Business, err = shopRep.GetBusiness(user.BusinessID.Int32)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if user.MaidID.Valid {
|
||||
user.Maid, err = shopRep.GetMaid(user.MaidID.Int32)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if user.MinerID.Valid {
|
||||
user.Miner, err = shopRep.GetMiner(user.MinerID.Int32)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if user.PairID.Valid {
|
||||
user.Pair, err = rep.GetById(int(user.PairID.Int64))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if user.FractionID.Valid {
|
||||
fractionRep := NewFractionRepository(rep.db)
|
||||
user.Fraction, err = fractionRep.GetById(user.FractionID.Int32)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
return user, err
|
||||
}
|
||||
|
||||
func (rep *UserRepository) Update(user *User) (*User, error) {
|
||||
_, err := rep.db.NamedExec(
|
||||
`UPDATE users SET balance=:balance, name=:name, group_id=:group_id, level=:level, exp=:exp,
|
||||
@@ -152,8 +207,21 @@ func (rep *UserRepository) Update(user *User) (*User, error) {
|
||||
|
||||
func (rep *UserRepository) GetAll() ([]*User, error) {
|
||||
users := make([]*User, 0)
|
||||
err := rep.db.Select(&users, "SELECT * FROM users ORDER BY id;")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return users, nil
|
||||
outUsers := make([]*User, len(users))
|
||||
for i, user := range users {
|
||||
u, err := rep.GetJoins(user)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
outUsers[i] = u
|
||||
}
|
||||
|
||||
return outUsers, nil
|
||||
}
|
||||
|
||||
func CountLevel(userXp int) (int, int) {
|
||||
|
||||
8
go.mod
8
go.mod
@@ -3,18 +3,18 @@ module kurumibot
|
||||
go 1.25
|
||||
|
||||
require (
|
||||
git.nix13.pw/scuroneko/laniakea v0.3.0
|
||||
git.nix13.pw/scuroneko/slog v1.0.0
|
||||
git.nix13.pw/scuroneko/laniakea v0.3.5
|
||||
git.nix13.pw/scuroneko/slog v1.0.2
|
||||
github.com/google/uuid v1.6.0
|
||||
github.com/joho/godotenv v1.5.1
|
||||
github.com/lib/pq v1.10.9
|
||||
github.com/lib/pq v1.11.0
|
||||
github.com/redis/go-redis/v9 v9.17.3
|
||||
github.com/shopspring/decimal v1.4.0
|
||||
github.com/vinovest/sqlx v1.7.1
|
||||
go.mongodb.org/mongo-driver/v2 v2.5.0
|
||||
)
|
||||
|
||||
//replace git.nix13.pw/scuroneko/laniakea v0.3.0 => ./laniakea
|
||||
//replace git.nix13.pw/scuroneko/laniakea v0.3.5 => ./laniakea
|
||||
|
||||
require (
|
||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||
|
||||
12
go.sum
12
go.sum
@@ -1,9 +1,9 @@
|
||||
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
||||
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
||||
git.nix13.pw/scuroneko/laniakea v0.3.0 h1:Hx0FPQaEtorcly0ILLnWCj4IPYuxpRCYVmwqNjKdCG4=
|
||||
git.nix13.pw/scuroneko/laniakea v0.3.0/go.mod h1:OVSuOuAQLUwBoFWH/+oTlQqwra1e49zED9Xoc9DeJcg=
|
||||
git.nix13.pw/scuroneko/slog v1.0.0 h1:PI0YePrmCopjrljUfwCtBIEwNYB+PBgDzPcCXbetpcE=
|
||||
git.nix13.pw/scuroneko/slog v1.0.0/go.mod h1:3Qm2wzkR5KjwOponMfG7TcGSDjmYaFqRAmLvSPTuWJI=
|
||||
git.nix13.pw/scuroneko/laniakea v0.3.5 h1:5eHpZ5/jHmNcImpa5fl4XUouQZsyyLaWA1ks6sg82z0=
|
||||
git.nix13.pw/scuroneko/laniakea v0.3.5/go.mod h1:ku3xWszXrB4elK7R4AqIn8GMKpWBV2pEnrpAZqxeMLQ=
|
||||
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/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=
|
||||
@@ -26,8 +26,8 @@ github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||
github.com/klauspost/compress v1.18.3 h1:9PJRvfbmTabkOX8moIpXPbMMbYN60bWImDDU7L+/6zw=
|
||||
github.com/klauspost/compress v1.18.3/go.mod h1:R0h/fSBs8DE4ENlcrlib3PsXS61voFxhIs2DeRhCvJ4=
|
||||
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
|
||||
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||
github.com/lib/pq v1.11.0 h1:aJpnw24caDH5XfSwI/tSUnN8RJRNqbNyArYazaGulzw=
|
||||
github.com/lib/pq v1.11.0/go.mod h1:/p+8NSbOcwzAEI7wiMXFlgydTwcgTr3OSKMsD2BitpA=
|
||||
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
|
||||
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
|
||||
@@ -50,19 +50,18 @@ func passiveIncome(b *laniakea.Bot) error {
|
||||
waifuRep := psql.NewWaifuRepository(ctx)
|
||||
userRep := psql.NewUserRepository(ctx)
|
||||
|
||||
for {
|
||||
users, err := userRep.GetAll()
|
||||
if err != nil {
|
||||
b.Logger().Error(err)
|
||||
continue
|
||||
return err
|
||||
}
|
||||
b.Logger().Infof("Loaded %d users\n", len(users))
|
||||
|
||||
for _, user := range users {
|
||||
if user.Business == nil && user.Maid == nil && user.Miner == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if time.Now().Before(user.IncomeTime.Add(time.Hour * 3)) {
|
||||
if time.Now().Before(user.IncomeTime.Add(time.Hour)) {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -98,7 +97,7 @@ func passiveIncome(b *laniakea.Bot) error {
|
||||
user.ExpIncome += int(expIncome.IntPart())
|
||||
user.MoneyIncome = user.MoneyIncome.Add(moneyIncome)
|
||||
user.BtcIncome = user.BtcIncome.Add(btcIncome)
|
||||
user.IncomeTime = time.Now().Add(-time.Hour * 2)
|
||||
user.IncomeTime = time.Now()
|
||||
|
||||
_, err = userRep.Update(user)
|
||||
if err != nil {
|
||||
@@ -108,7 +107,7 @@ func passiveIncome(b *laniakea.Bot) error {
|
||||
|
||||
b.Logger().Debug(fmt.Sprintf("У %d было пассивно собрано. След. сбор через час\n", user.ID))
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func profile(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
func InitLogsPlugin() {}
|
||||
func InitLogMiddleware() *laniakea.Middleware {
|
||||
func InitLogMiddleware() laniakea.Middleware {
|
||||
middle := laniakea.NewMiddleware("LogMiddleware")
|
||||
middle = middle.SetExecutor(logMiddleware).SetAsync(true)
|
||||
return middle.Build()
|
||||
@@ -41,6 +41,9 @@ type DatabaseWriter struct {
|
||||
|
||||
func (w *DatabaseWriter) Print(level slog.LogLevel, prefix string, traceback []*slog.MethodTraceback, messages ...any) error {
|
||||
t := time.Now()
|
||||
if messages[len(messages)-1] == "\n" {
|
||||
messages = messages[:len(messages)-1]
|
||||
}
|
||||
entry := &mdb.ConsoleLogEntry{
|
||||
Level: level.GetName(),
|
||||
Prefix: prefix,
|
||||
|
||||
@@ -610,8 +610,8 @@ func compress(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
}
|
||||
|
||||
//compressModel := "anthropic/claude-sonnet-4"
|
||||
//compressModel := "gpt-5.1"
|
||||
compressModel := "deepseek-ai/deepseek-v3.2"
|
||||
compressModel := "gpt-5.1"
|
||||
//compressModel := "deepseek-ai/deepseek-v3.1-terminus"
|
||||
api := ai.NewOpenAIAPI(ai.GPTBaseUrl, "", compressModel)
|
||||
defer api.Close()
|
||||
res, err := api.CompressChat(messages)
|
||||
@@ -625,6 +625,8 @@ func compress(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
compressedHistory := strings.TrimSpace(res.Choices[0].Message.Content)
|
||||
compressedHistory = strings.ReplaceAll(compressedHistory, "*", "")
|
||||
|
||||
m.Edit(compressedHistory)
|
||||
return
|
||||
chatId = uuid.New().String()
|
||||
err = redisRpRep.SetChatId(ctx.FromID, waifuId, chatId)
|
||||
if err != nil {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package ai
|
||||
|
||||
const GPTBaseUrl = "https://chat.gpt-chatbot.ru/api/openai"
|
||||
const CompressPrompt = "Сделай выжимку нашего диалога. Сохрани все ключевые моменты(например сколько одежды, расположение, основные действия и фразы и тд.) из каждого сообщения, но никогда не копируй описание персонажа(цвет волос и глаз, характер и т.д.). Если в истории уже есть выжимка, проанализируй размер и информацию. Если выжимка короткая, скопируй её с минимальными изменениями, а если длинная, то сократи, не упуская деталей. Всегда копируй основные моменты из выжимки, если таковая имеется. Для моих сообщений используй обращение во втором лице(ты, вы), для своих в первом(я). Всегда называй вещи своими именами и не используй Markdown форматирование."
|
||||
const CompressPrompt = "Сделай подробную выжимку нашего диалога. Сохрани все ключевые моменты(например сколько одежды, расположение, основные действия и фразы и тд.) из каждого сообщения, но никогда не копируй описание персонажа(цвет волос и глаз, характер и т.д.). Для моих сообщений используй обращение во втором лице(ты, вы), для своих в первом(я). Всегда называй вещи своими именами."
|
||||
|
||||
//const PawanBaseURL = "https://api.pawan.krd"
|
||||
//var CosmoRPUrl = fmt.Sprintf("%s/cosmosrp-2.5", PawanBaseURL)
|
||||
|
||||
Reference in New Issue
Block a user