package jrrp

import (
	"fmt"

	"git.lxtend.com/lixiangwuxian/qqbot/constants"
	"git.lxtend.com/lixiangwuxian/qqbot/handler"
	"git.lxtend.com/lixiangwuxian/qqbot/model"
	"git.lxtend.com/lixiangwuxian/qqbot/service/jrrp"
)

var jrrpInstance *jrrp.Jrrp

func init() {
	jrrpInstance = jrrp.NewJrrp()
	handler.RegisterHandler("今日人品", jrrpHandler, constants.LEVEL_USER)
	handler.RegisterHandler("jrrp", jrrpHandler, constants.LEVEL_USER)
	handler.RegisterHelpInform("今日人品/jrrp", "今日人品", "查询今日人品")
}

func jrrpHandler(msg model.Message) (reply *model.Reply) {
	luck, _ := jrrpInstance.GetJrrp(fmt.Sprint(msg.UserId))
	nickname := msg.UserNickName
	if msg.GroupInfo.IsGroupMsg && msg.GroupInfo.UserCard != "" {
		nickname = msg.GroupInfo.UserCard
	}
	return &model.Reply{
		ReplyMsg:       nickname + "同学你好，你的今日人品是：" + fmt.Sprint(luck),
		ReferOriginMsg: true,
		FromMsg:        msg,
	}
}
