package newbond

import (
	"git.lxtend.com/lixiangwuxian/qqbot/constants"
	"git.lxtend.com/lixiangwuxian/qqbot/handler"
	"git.lxtend.com/lixiangwuxian/qqbot/model"
)

func init() {
	handler.RegisterHandler("监听新债", listenBond, constants.LEVEL_USER)
	handler.RegisterHelpInform("监听新债", "新债", "开启新债监听")
	handler.RegisterHandler("取消监听新债", unListenBond, constants.LEVEL_USER)
	handler.RegisterHelpInform("取消监听新债", "新债", "关闭新债监听")
}

func listenBond(msg model.Message) (reply *model.Reply) {
	if err := AddGroupListen(int(msg.GroupInfo.GroupId)); err != nil {
		return &model.Reply{
			ReplyMsg:       "开启新债监听失败,报错: " + err.Error(),
			ReferOriginMsg: true,
			FromMsg:        msg,
		}
	}
	return &model.Reply{
		ReplyMsg:       "开启新债监听成功",
		ReferOriginMsg: true,
		FromMsg:        msg,
	}
}

func unListenBond(msg model.Message) (reply *model.Reply) {
	if err := RemoveGroupListen(int(msg.GroupInfo.GroupId)); err != nil {
		return &model.Reply{
			ReplyMsg:       "关闭新债监听失败,报错: " + err.Error(),
			ReferOriginMsg: true,
			FromMsg:        msg,
		}
	}
	return &model.Reply{
		ReplyMsg:       "关闭新债监听成功",
		ReferOriginMsg: true,
		FromMsg:        msg,
	}
}
