package drawback

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

func init() {
	handler.RegisterRegexHandler(`撤回`, drawback, constants.LEVEL_USER)
	handler.RegisterHelpInform("撤回", "drawback", "发送 <引用消息>撤回 撤回消息")
}

func drawback(msg model.Message) *model.Reply {
	msgIdToDrawback := qq_message.ReplyMessage{}
	if err := msgIdToDrawback.ParseMessage(msg.RawMsg); err != nil {
		return &model.Reply{
			ReplyMsg:       "",
			ReferOriginMsg: false,
			FromMsg:        msg,
		}
	}
	action.ActionManager.DrawbackMsg(int32(msgIdToDrawback.Data.ID))
	return &model.Reply{
		ReplyMsg:       "",
		ReferOriginMsg: false,
		FromMsg:        msg,
	}
}
