示例#1
0
文件: url.go 项目: yetist/xmppbot
func (m *Url) GetHelper(text string) string {
	if strings.Contains(text, "http://") || strings.Contains(text, "https://") {
		for k, url := range GetUrls(text) {
			if url != "" {
				timeout := time.Duration(m.Option["timeout"].(int64))
				res, body, err := utils.HttpOpen(url, timeout, "")
				if err != nil || res.StatusCode != http.StatusOK {
					return fmt.Sprintf("对不起,无法打开此<a href='%s'>链接</a>", url)
				}
				if strings.HasPrefix(res.Header.Get("Content-Type"), "text/html") {
					title := utils.GetUTF8HtmlTitle(string(body))
					if title == "" {
						return fmt.Sprintf("报歉,无法得到<a href='%s'>链接</a>标题", url)
					} else {
						return fmt.Sprintf("发链接了,标题是[<a href='%s'>%s</a>]", url, title)
					}
				} else if strings.HasPrefix(res.Header.Get("Content-Type"), "image/") {
					img := utils.GetBase64Image(body, m.Option["width"].(int), m.Option["height"].(int))
					return fmt.Sprintf("发<a href='%s'>图片</a>了:<br/><img alt='点击看大图' src='%s'/>", url, img)
				} else {
					println(k, url, "发了其它类型文件")
				}
			}
		}
	}
	return ""
}
示例#2
0
文件: about.go 项目: yetist/xmppbot
func getPubIP() (ip string) {
	if _, body, err := utils.HttpOpen("http://cip.cc", 5, utils.UserAgentCurl); err == nil {
		tokens := strings.SplitN(string(body), "\n", 2)
		if len(tokens) == 2 {
			ipaddr := tokens[0]
			pos := strings.LastIndex(strings.TrimSpace(ipaddr), " ")
			ip = "public: " + strings.TrimSpace(ipaddr[pos:])
			return
		}
	}
	return ""
}