runners and fixes
This commit is contained in:
@@ -29,7 +29,8 @@ func RegisterEconomy(bot *laniakea.Bot) {
|
||||
|
||||
economy = economy.Command(about, "about", "о боте")
|
||||
|
||||
//go passiveIncome(bot)
|
||||
runner := laniakea.NewRunner("economy.PassiveIncome", passiveIncome).Timeout(time.Minute).Build()
|
||||
bot.AddRunner(runner)
|
||||
|
||||
bot.AddPlugins(economy.Build())
|
||||
}
|
||||
@@ -44,64 +45,71 @@ func about(ctx *laniakea.MsgContext, _ *laniakea.DatabaseContext) {
|
||||
ctx.Answer(strings.Join(out, "\n"))
|
||||
}
|
||||
|
||||
//func passiveIncome(b *laniakea.Bot) {
|
||||
// for {
|
||||
// time.Sleep(time.Minute * 5)
|
||||
//
|
||||
// users, err := psql.GetAllUsers()
|
||||
// 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 := psql.GetUserWaifus(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)
|
||||
// psql.UpdateUser(user)
|
||||
//
|
||||
// b.Logger().Debug(fmt.Sprintf("У %d было пассивно собрано. След. сбор через час\n", user.ID))
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
func passiveIncome(b *laniakea.Bot) error {
|
||||
ctx := b.GetDBContext()
|
||||
waifuRep := psql.NewWaifuRepository(ctx)
|
||||
userRep := psql.NewUserRepository(ctx)
|
||||
|
||||
for {
|
||||
users, err := userRep.GetAll()
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func profile(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
rep := psql.NewUserRepository(db)
|
||||
|
||||
Reference in New Issue
Block a user