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) {
|
||||
|
||||
Reference in New Issue
Block a user