示例#1
0
func ReplySlap(pm data.Privmsg, config *data.Config) (string, error) {
	slap, err := slapAction(strings.Join(pm.Message[1:], " "))
	if err != nil {
		return "", err
	}
	return cmd.PrivmsgAction(pm.Target, slap), nil
}
示例#2
0
func ReplyGIF(pm data.Privmsg, config *data.Config) (string, error) {
	msg := strings.Join(pm.Message[1:], " ")
	giphy, err := searchGiphy(msg, config)
	if err != nil {
		return "", err
	}
	if len(giphy.Data) > 0 {
		m := fmt.Sprintf("%s/media/%s/giphy.gif", config.Giphy, giphy.Data[rand.Intn(len(giphy.Data))].ID)
		return cmd.Privmsg(pm.Target, m), nil
	}
	return cmd.PrivmsgAction(pm.Target, "zzzzz..."), nil
}
示例#3
0
func ReplyUd(pm data.Privmsg, config *data.Config) (string, error) {
	if len(pm.Message) >= 2 {
		term := url.QueryEscape(strings.TrimSpace(strings.Join(pm.Message[1:], " ")))
		source := fmt.Sprintf("%s?term=%s", config.Ud, term)

		doc, err := goquery.NewDocument(source)
		if err != nil {
			return "", nil
		}

		result := formatResult(doc.Find("div.meaning").First().Text(), source, config.UdMaxWords)
		if result != "" {
			return cmd.Privmsg(pm.Target, result), nil
		} else {
			return cmd.PrivmsgAction(pm.Target, "zzzzz..."), nil
		}
	}
	return "", nil
}
示例#4
0
func ReplyDdg(pm data.Privmsg, config *data.Config) (string, error) {
	if len(pm.Message) >= 2 {
		term := escape(strings.Join(pm.Message[1:], " "))
		source := fmt.Sprintf("%s/html/?q=%s&kl=us-en&kp=-1", config.Ddg, term)

		doc, err := goquery.NewDocument(source)
		if err != nil {
			return "", nil
		}

		result := doc.Find("div.results_links").Not("div.web-result-sponsored") // excluded sponsored result
		title := strings.TrimSpace(result.Find("a.large").First().Text())
		url := strings.TrimSpace(result.Find("div.url").First().Text())

		if title != "" && url != "" {
			return cmd.Privmsg(pm.Target, fmt.Sprintf("%s (link: %s)", title, url)), nil
		} else {
			return cmd.PrivmsgAction(pm.Target, "zzzzz..."), nil
		}
	}
	return "", nil
}
示例#5
0
func ReplyWik(pm data.Privmsg, config *data.Config) (string, error) {
	msg := strings.Join(pm.Message[1:], " ")
	if strings.TrimSpace(msg) != "" {
		ddg, err := queryDuckDuckGo(msg, config)
		if err != nil {
			return "", err
		}
		if ddg.AbstractText != "" && ddg.AbstractURL != "" {
			words := strings.Split(ddg.AbstractText, " ")
			var m string
			if len(words) > config.WikMaxWords {
				text := strings.Join(words[:config.WikMaxWords], " ")
				m = fmt.Sprintf("%s... (source: %s)", text, ddg.AbstractURL)
			} else {
				m = fmt.Sprintf("%s (source: %s)", ddg.AbstractText, ddg.AbstractURL)
			}
			return cmd.Privmsg(pm.Target, m), nil
		}
		return cmd.PrivmsgAction(pm.Target, "zzzzz..."), nil
	}
	return "", nil
}
示例#6
0
func ReplyPing(pm data.Privmsg, config *data.Config) (string, error) {
	return cmd.PrivmsgAction(pm.Target, "meows"), nil
}