package getweb

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

func init() {
	handler.RegisterHandler("上网", getweb)
}

func getweb(msg model.Message) (reply model.Reply) {
	if len(msg.RawMsg) <= len("上网 ") {
		return model.Reply{}
	}
	url := msg.RawMsg[len("上网 "):]
	if err := util.ScreenshotURL(url, "./tmp/getweb/url.png", 0, 0, 0, 0, 0, 0, ""); err != nil {
		return model.Reply{
			ReplyMsg:       err.Error(),
			ReferOriginMsg: true,
			FromMsg:        msg,
		}
	}
	return model.Reply{
		ReplyMsg:       "[CQ:image,file=file:///root/qqbot/tmp/getweb/url.png]",
		ReferOriginMsg: true,
		FromMsg:        msg,
	}
}
