refactoring, fixes and laniakea v0.8
This commit is contained in:
@@ -2,20 +2,21 @@ package plugins
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"kurumibot/database/psql"
|
||||
"kurumibot/utils"
|
||||
"math"
|
||||
"math/rand/v2"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"ymgb/database"
|
||||
"ymgb/database/psql"
|
||||
"ymgb/utils"
|
||||
|
||||
"git.nix13.pw/scuroneko/laniakea"
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
func RegisterEconomy(bot *laniakea.Bot) {
|
||||
p := laniakea.NewPlugin("Economy")
|
||||
func RegisterEconomy(bot *laniakea.Bot[database.Context]) *laniakea.Plugin[database.Context] {
|
||||
p := laniakea.NewPlugin[database.Context]("Economy")
|
||||
p.AddCommand(p.NewCommand(profile, "profile"))
|
||||
p.AddCommand(p.NewCommand(profile, "профиль").SkipCommandAutoGen())
|
||||
p.AddCommand(p.NewCommand(work, "work"))
|
||||
@@ -33,14 +34,13 @@ func RegisterEconomy(bot *laniakea.Bot) {
|
||||
p.AddCommand(p.NewCommand(aboutGroup, "group"))
|
||||
p.AddCommand(p.NewCommand(aboutGroup, "о группе").SkipCommandAutoGen())
|
||||
|
||||
bot.AddRunner(laniakea.NewRunner(
|
||||
bot.AddRunner(*laniakea.NewRunner[database.Context](
|
||||
"economy.PassiveIncome", passiveIncome,
|
||||
).Timeout(time.Minute).Build())
|
||||
|
||||
bot.AddPlugins(p)
|
||||
).Timeout(time.Minute))
|
||||
return p
|
||||
}
|
||||
|
||||
func passiveIncome(b *laniakea.Bot) error {
|
||||
func passiveIncome(b *laniakea.Bot[database.Context]) error {
|
||||
ctx := b.GetDBContext()
|
||||
waifuRep := psql.NewWaifuRepository(ctx)
|
||||
userRep := psql.NewUserRepository(ctx)
|
||||
@@ -49,7 +49,7 @@ func passiveIncome(b *laniakea.Bot) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
b.Logger().Debugf("Loaded %d users\n", len(users))
|
||||
b.GetLogger().Debugf("Loaded %d users\n", len(users))
|
||||
|
||||
for _, user := range users {
|
||||
if user.Business == nil && user.Maid == nil && user.Miner == nil {
|
||||
@@ -76,7 +76,7 @@ func passiveIncome(b *laniakea.Bot) error {
|
||||
|
||||
waifus, err := waifuRep.GetByUserId(user.ID)
|
||||
if err != nil {
|
||||
b.Logger().Error(err)
|
||||
b.GetLogger().Errorln(err)
|
||||
continue
|
||||
}
|
||||
for _, waifu := range waifus {
|
||||
@@ -96,16 +96,16 @@ func passiveIncome(b *laniakea.Bot) error {
|
||||
|
||||
_, err = userRep.Update(&user)
|
||||
if err != nil {
|
||||
b.Logger().Error(err)
|
||||
b.GetLogger().Errorln(err)
|
||||
continue
|
||||
}
|
||||
|
||||
b.Logger().Debug(fmt.Sprintf("У %d было пассивно собрано. След. сбор через час\n", user.ID))
|
||||
b.GetLogger().Debugln(fmt.Sprintf("У %d было пассивно собрано. След. сбор через час\n", user.ID))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func profile(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
func profile(ctx *laniakea.MsgContext, db *database.Context) {
|
||||
rep := psql.NewUserRepository(db)
|
||||
user, err := rep.GetOrCreate(ctx.FromID, ctx.Msg.From.FirstName)
|
||||
if err != nil {
|
||||
@@ -158,7 +158,7 @@ func profile(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
ctx.Answer(strings.Join(out, "\n"))
|
||||
}
|
||||
|
||||
func work(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
func work(ctx *laniakea.MsgContext, db *database.Context) {
|
||||
rep := psql.NewUserRepository(db)
|
||||
user, err := rep.GetOrCreate(ctx.FromID, ctx.Update.Message.From.FirstName)
|
||||
if err != nil {
|
||||
@@ -207,7 +207,7 @@ func work(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
))
|
||||
}
|
||||
|
||||
func collect(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
func collect(ctx *laniakea.MsgContext, db *database.Context) {
|
||||
rep := psql.NewUserRepository(db)
|
||||
user, err := rep.GetOrCreate(ctx.FromID, ctx.Update.Message.From.FirstName)
|
||||
if err != nil {
|
||||
@@ -312,11 +312,11 @@ func collect(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
ctx.Answer(strings.Join(out, "\n"))
|
||||
}
|
||||
|
||||
func code(ctx *laniakea.MsgContext, _ *laniakea.DatabaseContext) {
|
||||
func code(ctx *laniakea.MsgContext, _ *database.Context) {
|
||||
// user, err := database.Get
|
||||
}
|
||||
|
||||
func vacancies(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
func vacancies(ctx *laniakea.MsgContext, db *database.Context) {
|
||||
worksRep := psql.NewWorkRepository(db)
|
||||
works, err := worksRep.GetAll()
|
||||
|
||||
@@ -336,7 +336,7 @@ func vacancies(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
ctx.Answer(strings.Join(out, "\n"))
|
||||
}
|
||||
|
||||
func getAJob(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
func getAJob(ctx *laniakea.MsgContext, db *database.Context) {
|
||||
if len(ctx.Args) == 0 {
|
||||
ctx.Answer("Недостаточно аргументов")
|
||||
return
|
||||
@@ -372,7 +372,7 @@ func getAJob(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
ctx.Answer("Ты успешно устроился на работу!")
|
||||
}
|
||||
|
||||
func aboutGroup(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
func aboutGroup(ctx *laniakea.MsgContext, db *database.Context) {
|
||||
userRep := psql.NewUserRepository(db)
|
||||
user, err := userRep.GetOrCreate(ctx.FromID, ctx.Msg.From.FirstName)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user