compress wip
This commit is contained in:
@@ -50,65 +50,64 @@ func passiveIncome(b *laniakea.Bot) error {
|
||||
waifuRep := psql.NewWaifuRepository(ctx)
|
||||
userRep := psql.NewUserRepository(ctx)
|
||||
|
||||
for {
|
||||
users, err := userRep.GetAll()
|
||||
users, err := userRep.GetAll()
|
||||
if err != nil {
|
||||
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)) {
|
||||
continue
|
||||
}
|
||||
|
||||
moneyIncome := decimal.NewFromInt(0)
|
||||
expIncome := decimal.NewFromInt(0)
|
||||
btcIncome := decimal.NewFromInt(0)
|
||||
|
||||
if user.Business != nil {
|
||||
moneyIncome = moneyIncome.Add(user.Business.Income).Mul(user.Group.Multiplier)
|
||||
}
|
||||
if user.Maid != nil {
|
||||
expIncome = expIncome.Add(user.Maid.Income).Mul(user.Group.Multiplier)
|
||||
}
|
||||
if user.Miner != nil {
|
||||
btcIncome = btcIncome.Add(user.Miner.Income).Mul(user.Group.Multiplier)
|
||||
}
|
||||
|
||||
waifus, err := waifuRep.GetByUserId(user.ID)
|
||||
if err != nil {
|
||||
b.Logger().Error(err)
|
||||
continue
|
||||
}
|
||||
for _, waifu := range waifus {
|
||||
moneyIncome = moneyIncome.Mul(waifu.MoneyBonus)
|
||||
expIncome = expIncome.Mul(waifu.ExpBonus)
|
||||
btcIncome = btcIncome.Mul(waifu.MoneyBonus)
|
||||
}
|
||||
|
||||
expIncome = expIncome.Mul(decimal.NewFromFloat(0.25))
|
||||
moneyIncome = moneyIncome.Mul(decimal.NewFromFloat(0.25))
|
||||
btcIncome = btcIncome.Mul(decimal.NewFromFloat(0.25))
|
||||
|
||||
user.ExpIncome += int(expIncome.IntPart())
|
||||
user.MoneyIncome = user.MoneyIncome.Add(moneyIncome)
|
||||
user.BtcIncome = user.BtcIncome.Add(btcIncome)
|
||||
user.IncomeTime = time.Now()
|
||||
|
||||
_, err = userRep.Update(user)
|
||||
if err != nil {
|
||||
b.Logger().Error(err)
|
||||
continue
|
||||
}
|
||||
|
||||
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)) {
|
||||
continue
|
||||
}
|
||||
|
||||
moneyIncome := decimal.NewFromInt(0)
|
||||
expIncome := decimal.NewFromInt(0)
|
||||
btcIncome := decimal.NewFromInt(0)
|
||||
|
||||
if user.Business != nil {
|
||||
moneyIncome = moneyIncome.Add(user.Business.Income).Mul(user.Group.Multiplier)
|
||||
}
|
||||
if user.Maid != nil {
|
||||
expIncome = expIncome.Add(user.Maid.Income).Mul(user.Group.Multiplier)
|
||||
}
|
||||
if user.Miner != nil {
|
||||
btcIncome = btcIncome.Add(user.Miner.Income).Mul(user.Group.Multiplier)
|
||||
}
|
||||
|
||||
waifus, err := waifuRep.GetByUserId(user.ID)
|
||||
if err != nil {
|
||||
b.Logger().Error(err)
|
||||
continue
|
||||
}
|
||||
for _, waifu := range waifus {
|
||||
moneyIncome = moneyIncome.Mul(waifu.MoneyBonus)
|
||||
expIncome = expIncome.Mul(waifu.ExpBonus)
|
||||
btcIncome = btcIncome.Mul(waifu.MoneyBonus)
|
||||
}
|
||||
|
||||
expIncome = expIncome.Mul(decimal.NewFromFloat(0.25))
|
||||
moneyIncome = moneyIncome.Mul(decimal.NewFromFloat(0.25))
|
||||
btcIncome = btcIncome.Mul(decimal.NewFromFloat(0.25))
|
||||
|
||||
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)
|
||||
|
||||
_, err = userRep.Update(user)
|
||||
if err != nil {
|
||||
b.Logger().Error(err)
|
||||
continue
|
||||
}
|
||||
|
||||
b.Logger().Debug(fmt.Sprintf("У %d было пассивно собрано. След. сбор через час\n", user.ID))
|
||||
}
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user