40 lines
913 B
Go
40 lines
913 B
Go
package getweb
|
|
|
|
import (
|
|
"git.lxtend.com/qqbot/handler"
|
|
"git.lxtend.com/qqbot/model"
|
|
"git.lxtend.com/qqbot/util"
|
|
)
|
|
|
|
func init() {
|
|
handler.RegisterHandler("上网", getweb)
|
|
handler.RegisterHelpInform("上网", "上网 <URL> 截取网页")
|
|
}
|
|
|
|
func getweb(msg model.Message) (reply model.Reply) {
|
|
if len(msg.RawMsg) <= len("上网 ") {
|
|
return model.Reply{}
|
|
}
|
|
url := msg.RawMsg[len("上网 "):]
|
|
url = formatURL(url)
|
|
if err := util.ScreenshotURL(url, "./tmp/getweb/url.png", 1620, 1960, 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,
|
|
}
|
|
}
|
|
|
|
func formatURL(url string) string {
|
|
if url[:7] != "http://" && url[:8] != "https://" {
|
|
return "http://" + url
|
|
}
|
|
return url
|
|
}
|