Example #1
0
// Help displays help for all bot commands.
func Help(p *lib.Privmsg) bool {
	if !strings.HasPrefix(p.Msg, "..help") {
		return false
	}

	nick := p.Event.Nick

	lib.Say(p, fmt.Sprintf("%s: List of commands:", nick))

	for _, s := range helpMsgs {
		lib.Say(p, fmt.Sprintf("%s: %s", nick, s))
	}

	return true
}
Example #2
0
func EchoName(p *lib.Privmsg) bool {
	if !strings.HasPrefix(p.Msg, fmt.Sprintf("%s!", nick)) {
		return false
	}
	lib.Say(p, fmt.Sprintf("%s!", p.Event.Nick))
	return true
}
Example #3
0
// Url attempts to fetch the title of the HTML document returned by a URL
func Url(p *lib.Privmsg) bool {
	urls := xurls.Strict.FindAllString(p.Msg, -1)

	for _, urlStr := range urls {
		url, err := urllib.Parse(urlStr)
		if err != nil {
			continue
		}
		if v, _ := validateUrl(url); !v {
			continue
		}
		host := url.Host
		title, err := getHtmlTitle(urlStr)
		if err != nil {
			continue
		}
		title = strings.Replace(title, "\n", "", -1)
		title = strings.Replace(title, "\r", "", -1)
		title = strings.TrimSpace(title)
		lib.Say(p, fmt.Sprintf("^ %s - [%s]", title, host))
	}

	// don't consume the message, in case there are commands in it
	return false
}
Example #4
0
func showDefinition(p *lib.Privmsg) {
	var def *urbandict.Definition
	var err error
	nick := p.Event.Nick
	isWotd := strings.HasPrefix(p.Msg, "..urban-wotd")
	if isWotd {
		def, err = urbandict.WordOfTheDay()
	} else if len(p.MsgArgs) == 1 {
		def, err = urbandict.Random()
	} else {
		def, err = urbandict.Define(strings.Join(p.MsgArgs[1:], " "))
	}
	if err != nil {
		lib.Say(p, fmt.Sprintf("%s: %s", nick, err.Error()))
		return
	}

	// TODO: implement max message length handling

	if isWotd {
		lib.Say(p, fmt.Sprintf("%s: Word of the day: \"%s\"", nick, def.Word))
	} else {
		lib.Say(p, fmt.Sprintf("%s: Top definition for \"%s\"", nick, def.Word))
	}
	for _, line := range strings.Split(def.Definition, "\r\n") {
		lib.Say(p, fmt.Sprintf("%s: %s", nick, line))
	}
	lib.Say(p, fmt.Sprintf("%s: Example:", nick))
	for _, line := range strings.Split(def.Example, "\r\n") {
		lib.Say(p, fmt.Sprintf("%s: %s", nick, line))
	}
	lib.Say(p, fmt.Sprintf("%s: permalink: %s", nick, def.Permalink))
}
Example #5
0
func showTrending(p *lib.Privmsg) {
	nick := p.Event.Nick

	trendingWords, err := urbandict.Trending()
	if err != nil {
		lib.Say(p, fmt.Sprintf("%s: %s", nick, err.Error()))
		return
	}

	lib.Say(p, fmt.Sprintf("%s: Top %d trending words:",
		nick,
		len(trendingWords)))

	for i, word := range trendingWords {
		lib.Say(p, fmt.Sprintf("%s: %d. %s", nick, i+1, word))
	}

	return
}
Example #6
0
func Insult(p *lib.Privmsg) bool {
	if !strings.HasPrefix(p.Msg, "..insult") {
		return false
	}

	if len(swears) == 0 {
		lib.Say(p, "error: no swears")
		return true
	}

	insultee := p.Event.Nick
	if len(p.MsgArgs) > 1 {
		insultee = strings.Join(p.MsgArgs[1:], " ")
	}

	response := fmt.Sprintf(
		"%s: you %s %s",
		insultee,
		swears[rand.Intn(len(swears))],
		swears[rand.Intn(len(swears))])

	lib.Say(p, response)
	return true
}