white-zone-bot/bot/handlers/check_points_btn_handler.go
2025-05-24 09:16:47 +06:00

31 lines
913 B
Go

package handlers
import (
"fmt"
"log/slog"
"github.com/theorift/white-zone-bot/bot"
"github.com/theorift/white-zone-bot/repositories"
"github.com/theorift/white-zone-bot/services"
"gopkg.in/telebot.v4"
)
func HandleCheckPointBtn(bot bot.Bot, userRepo repositories.UserRepository) {
bot.GetInstance().Handle(
&telebot.InlineButton{Unique: "check_points"},
func(ctx telebot.Context) error {
errMsg := "Sorry for the inconvenience! Something went wrong on our side. Please try again sometime later!"
senderID := ctx.Sender().ID
userService := services.NewUserService(senderID, userRepo)
pointCount, err := userService.GetPoints()
if err != nil {
slog.Error("Error checking user points.", "senderID", senderID)
return ctx.Send(errMsg)
}
msgText := fmt.Sprintf("You currently have %d points!", pointCount)
return ctx.Send(msgText)
},
)
}