示例#1
0
func ReplyQuote(pm data.Privmsg, config *data.Config) (string, error) {
	// Establish if we want to just return a single quote
	if len(pm.Message) == 2 {
		quoteID, err := strconv.ParseInt(pm.Message[1], 0, 0)
		if err == nil && quoteID > 0 {
			quoteStr, err := getQuote(quoteID)
			if err != nil {
				return "", err
			}
			return cmd.Privmsg(pm.Target, quoteStr), nil
		}
	}

	// Determine if this is a request for an existing quote, or attempting to
	// store a new one.
	msg := strings.Trim(strings.Join(pm.Message[1:], " "), " ")
	if strings.Count(msg, "\"") == 2 {
		if storeQuote(msg, pm.Source) {
			return cmd.Privmsg(pm.Target, "Got it!"), nil
		}
		return "", nil
	}

	// At this point the assumption is that we just want a random quote
	quoteStr, err := getRandomQuote()
	if err != nil {
		return "", err
	}
	return cmd.Privmsg(pm.Target, quoteStr), nil
}
示例#2
0
func ReplyJira(pm data.Privmsg, config *data.Config) (string, error) {
	msg := strings.Join(pm.Message[1:], " ")
	if strings.TrimSpace(msg) != "" {
		return cmd.Privmsg(pm.Target, config.Jira+"/browse/"+strings.ToUpper(msg)), nil
	}
	return cmd.Privmsg(pm.Target, config.Jira), nil
}
示例#3
0
func ReplyAsk(pm data.Privmsg, config *data.Config) (string, error) {
	msg := strings.Join(pm.Message[1:], " ")
	if strings.TrimSpace(msg) != "" {
		rand.Seed(time.Now().UnixNano())
		ors := strings.Split(msg, " or ")
		if len(ors) > 1 {
			return cmd.Privmsg(pm.Target, ors[rand.Intn(len(ors))]), nil
		}
		return cmd.Privmsg(pm.Target, [2]string{"yes!", "no..."}[rand.Intn(2)]), nil
	}
	return "", nil
}
示例#4
0
func ReplyBeertime(pm data.Privmsg, config *data.Config) (string, error) {
	td, err := timeDelta(config.Beertime.Day, config.Beertime.Hour, config.Beertime.Minute)
	if err != nil {
		return "", err
	}
	return cmd.Privmsg(pm.Target, td), nil
}
示例#5
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
}
示例#6
0
func ReplyTitle(pm data.Privmsg, config *data.Config) (string, error) {
	if len(pm.Message) == 2 {
		url := strings.TrimSpace(pm.Message[1])
		if url != "" {
			doc, err := goquery.NewDocument(url)
			if err != nil {
				return "", err
			}

			return cmd.Privmsg(pm.Target, doc.Find("title").Text()), nil
		}
	}
	return "", nil
}
示例#7
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
}
示例#8
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
}
示例#9
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
}
示例#10
0
func ReplyDay(pm data.Privmsg, config *data.Config) (string, error) {
	return cmd.Privmsg(pm.Target, strings.ToLower(time.Now().Weekday().String())), nil
}
示例#11
0
func ReplyVer(pm data.Privmsg, config *data.Config) (string, error) {
	return cmd.Privmsg(pm.Target, fmt.Sprintf("gerri version: %s", VERSION)), nil
}