package help

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

func init() {
	handler.RegisterHandler("!help", help, constants.LEVEL_BANNED)
}

func help(msg model.Message) (reply model.Reply) {
	var helpInfo string
	if len(util.SplitN(msg.RawMsg, 2)) == 1 {
		helpInfo = `!help [分类] 查看下面的分类功能`
		for k := range handler.HelpInforms {
			helpInfo += "\n" + k
		}
	} else {
		category := util.SplitN(msg.RawMsg, 2)[1]
		helpInfos := handler.HelpInforms[category]
		helpInfo = `以下是` + category + `的功能：`
		for _, v := range helpInfos {
			helpInfo += "\n" + v.Trigger + " : " + v.Inform
		}
	}
	return model.Reply{
		ReplyMsg:       helpInfo,
		ReferOriginMsg: false,
		FromMsg:        msg,
	}
}
