Ejemplo n.º 1
0
func setup(reg *callback.Registry, config map[string]interface{}) error {
	channels = make(map[string]map[string]Line)
	reg.AddCallback("PRIVMSG", func(conn *irc.Conn, line irc.Line, dst, text string) {
		if line.Src.Nick == "" {
			return
		}
		if matches := sedRegex.FindStringSubmatch(text); matches != nil {
			processMatches(conn, line, dst, matches)
		} else {
			lines := channels[dst]
			if lines == nil {
				lines = make(map[string]Line)
				channels[dst] = lines
			}
			lines[line.Src.Nick] = Line{Msg: text, Action: false}
		}
	})
	reg.AddCallback("ACTION", func(conn *irc.Conn, line irc.Line, dst, text string, isPrivate bool) {
		if line.Src.Nick == "" || isPrivate {
			return
		}
		if matches := sedRegex.FindStringSubmatch(text); matches != nil {
			processMatches(conn, line, dst, matches)
		} else {
			lines := channels[dst]
			if lines == nil {
				lines = make(map[string]Line)
				channels[dst] = lines
			}
			lines[line.Src.Nick] = Line{Msg: text, Action: true}
		}
	})
	return nil
}
Ejemplo n.º 2
0
func setup(reg *callback.Registry, config map[string]interface{}) error {
	reg.AddCallback("PRIVMSG", func(conn *irc.Conn, line irc.Line, dst, text string) {
		reply := dst
		if dst == conn.Me().Nick {
			reply = line.Src.Nick
		}
		if reply == "" {
			// what, the server sent us a privmsg?
			return
		}
		// allow voidbot to be addressed directly, and modify the response
		prefix := ""
		isDirected := false
		if strings.HasPrefix(text, fmt.Sprintf("%s: ", conn.Me().Nick)) {
			text = text[len(conn.Me().Nick)+2:]
			prefix = line.Src.Nick + ": "
			isDirected = true
		}
		// implement super awesome reaction logic here
		if strings.ToLower(text) == "herp" {
			plugin.Conn(conn).Notice(reply, prefix+utils.MatchCase("derp", text))
		} else if strings.ToLower(text) == "is me1000 drunk?" || (line.Src.Nick == "Me1000" && strings.ToLower(text) == "am i drunk?") {
			plugin.Conn(conn).Notice(reply, prefix+randResponse([]string{"yes", "always"}))
		} else if isDirected && strings.ToLower(text) == "botsnack" {
			plugin.Conn(conn).Notice(reply, prefix+randResponse([]string{"yum", "nom nom", "om nom nom"}))
		} else if isDirected && text == "<3" {
			plugin.Conn(conn).Notice(reply, prefix+"<3")
		}
	})
	return nil
}
Ejemplo n.º 3
0
func setupVine(reg *callback.Registry, config map[string]interface{}) error {
	reg.AddCallback("URL", func(conn *irc.Conn, line irc.Line, dst string, url *url.URL) {
		if url.Scheme == "http" || url.Scheme == "https" {
			if url.Host == "vine.co" || url.Host == "www.vine.co" {
				if url.Fragment != "noquote" {
					go processVineURL(plugin.Conn(conn), line, dst, url)
				}
			}
		}
	})
	return nil
}
Ejemplo n.º 4
0
func setup(reg *callback.Registry, config map[string]interface{}) error {
	reg.AddCallback("COMMAND", func(conn *irc.Conn, line irc.Line, cmd, arg, reply string, isPrivate bool) {
		if cmd == "alpha" {
			arg = strings.TrimSpace(arg)
			if arg == "" {
				plugin.Conn(conn).Notice(reply, "!alpha requires an argument")
			} else {
				go runQuery(plugin.Conn(conn), arg, reply)
			}
		}
	})
	return nil
}
Ejemplo n.º 5
0
func setup(reg *callback.Registry, config map[string]interface{}) error {
	reg.AddCallback("URL", func(conn *irc.Conn, line irc.Line, dst string, url *url.URL) {
		if url.Scheme == "http" || url.Scheme == "https" {
			if url.Host == "alpha.app.net" {
				comps := strings.Split(strings.TrimLeft(url.Path, "/"), "/")
				if len(comps) > 2 && comps[1] == "post" {
					id := comps[2]
					go fetchADNPost(plugin.Conn(conn), line, dst, id)
				}
			}
		}
	})
	return nil
}
Ejemplo n.º 6
0
func setup(reg *callback.Registry, config map[string]interface{}) error {
	reg.AddCallback("COMMAND", func(conn *irc.Conn, line irc.Line, cmd string, arg string, reply string, isPrivate bool) {
		if cmd == "dogecoin" && !isPrivate {
			arg = strings.ToLower(strings.TrimSpace(arg))
			if arg == "" {
				msg := "dogecoin is: "
				if enabled {
					msg += "ON"
				} else {
					msg += "OFF"
				}
				plugin.Conn(conn).Notice(reply, msg)
			} else if arg == "on" || arg == "off" {
				if line.Src.Nick == "Me1000" {
					plugin.Conn(conn).Notice(reply, "no")
				} else if arg == "on" {
					enabled = true
					plugin.Conn(conn).Notice(reply, "dogecoin enabled")
				} else if arg == "off" {
					enabled = false
					plugin.Conn(conn).Notice(reply, "dogecoin disabled")
				}
			} else {
				plugin.Conn(conn).Notice(reply, "derp?")
			}
		}
	})
	reg.AddCallback("PRIVMSG", func(conn *irc.Conn, line irc.Line, dst, text string) {
		if enabled {
			derptext := utils.ReplaceAllFold(text, "bitcoin", "dogecoin")
			if derptext != "" {
				plugin.Conn(conn).Notice(dst, derptext)
				return
			}
			if subs := btcRegex.FindStringSubmatch(text); subs != nil {
				// we found a construct like "0.01 BTC"
				if val, err := strconv.ParseFloat(subs[1], 64); err == nil {
					const kUpperLimit = 1000
					exchangeRate := float64(rand.Intn(kUpperLimit*100)) / 100.0
					val *= exchangeRate
					val = math.Floor(val*100.0) / 100.0
					msg := fmt.Sprintf("%s: that's almost $%.2f!", line.Src.Nick, val)
					plugin.Conn(conn).Notice(dst, msg)
				}
			}
		}
	})
	return nil
}
Ejemplo n.º 7
0
func setupTweet(reg *callback.Registry, config map[string]interface{}) error {
	reg.AddCallback("URL", func(conn *irc.Conn, line irc.Line, dst string, url *url.URL) {
		if url.Scheme == "http" || url.Scheme == "https" {
			if url.Host == "twitter.com" || url.Host == "www.twitter.com" {
				if url.Fragment != "noquote" {
					username, tweet_id := parseTwitterURL(url)
					if username != "" && tweet_id != "" {
						go processTweetURL(plugin.Conn(conn), line, dst, username, tweet_id)
					}
				}
			}
		}
	})
	return nil
}
Ejemplo n.º 8
0
func setup(reg *callback.Registry, config map[string]interface{}) error {
	reg.AddCallback("URL", func(conn *irc.Conn, line irc.Line, dst string, url *url.URL) {
		if url.Scheme == "http" || url.Scheme == "https" {
			if url.Host == "youtube.com" || url.Host == "www.youtube.com" {
				if url.Path == "/watch" {
					if key, ok := url.Query()["v"]; ok && key != nil {
						go handleYoutubeVideo(plugin.Conn(conn), line, dst, key[0], url.Fragment)
					}
				}
			} else if url.Host == "youtu.be" {
				go handleYoutubeVideo(plugin.Conn(conn), line, dst, strings.TrimLeft(url.Path, "/"), url.Fragment)
			}
		}
	})
	return nil
}
Ejemplo n.º 9
0
func setup(reg *callback.Registry, config map[string]interface{}) error {
	reg.AddCallback("URL", func(conn *irc.Conn, line irc.Line, dst string, url *url.URL) {
		if url.Scheme == "http" || url.Scheme == "https" {
			if url.Host == "vimeo.com" || url.Host == "www.vimeo.com" {
				path := url.Path
				if strings.HasPrefix(path, "/") {
					path = path[1:]
				}
				if len(path) > 0 && strings.IndexFunc(path, func(r rune) bool { return !unicode.IsDigit(r) }) == -1 {
					go handleVimeo(plugin.Conn(conn), line, dst, path)
				}
			}
		}
	})
	return nil
}
Ejemplo n.º 10
0
func setup(reg *callback.Registry, config map[string]interface{}) error {
	reg.AddCallback("PRIVMSG", func(conn *irc.Conn, line irc.Line, dst, text string) {
		if matches := stockRegex.FindAllString(text, -1); matches != nil {
			for i, match := range matches {
				matches[i] = match[1:] // trim off the $
			}
			if dst == conn.Me().Nick {
				dst = line.Src.Nick
			}
			if dst == "" {
				// wtf?
				return
			}
			go queryStocks(matches, plugin.Conn(conn), dst)
		}
	})
	return nil
}
Ejemplo n.º 11
0
func setupFlickr(reg *callback.Registry, config map[string]interface{}) error {
	if key, ok := config["api_key"].(string); ok {
		api_key = key
	} else {
		// can't do much without an API key
		return nil
	}
	reg.AddCallback("URL", func(conn *irc.Conn, line irc.Line, dst string, url *url.URL) {
		if url.Host == "flickr.com" || url.Host == "www.flickr.com" {
			if photo_id, set_id, ok := parseFlickrURL(url); ok {
				if photo_id != "" {
					go processFlickrPhoto(plugin.Conn(conn), line, dst, photo_id)
				} else {
					go processFlickrSet(plugin.Conn(conn), line, dst, set_id)
				}
			}
		}
	})
	return nil
}
Ejemplo n.º 12
0
func setupURLs(reg *callback.Registry, config map[string]interface{}) error {
	var err error
	historyDB, err = database.Open("sqlite3", "./history.db")
	if err != nil {
		return err
	}

	sqls := []string{
		"CREATE TABLE IF NOT EXISTS seen (id integer not null primary key, url text not null, nick text, src text not null, dst text not null, timestamp datetime not null)",
		"CREATE INDEX IF NOT EXISTS url_idx ON seen (url, dst)",
	}
	for _, sqlstr := range sqls {
		_, err = historyDB.Exec(sqlstr)
		if err != nil {
			return err
		}
	}

	reg.AddCallback("PRIVMSG", func(conn *irc.Conn, line irc.Line, dst, text string) {
		matches := URLRegex.FindAllStringSubmatch(text, -1)
		if matches != nil {
			for _, submatches := range matches {
				urlStr := submatches[1]
				if u, err := url.Parse(urlStr); err == nil && u.Host != "" {
					reg.Dispatch("URL", conn, line, dst, u)
				}
			}
		}
	})

	reg.AddCallback("URL", func(conn *irc.Conn, line irc.Line, dst string, url *url.URL) {
		handleURL(conn, historyDB, line, dst, url)
	})

	reg.AddCallback("COMMAND", func(conn *irc.Conn, line irc.Line, cmd, arg, dst string, isPrivate bool) {
		if cmd == "urls" {
			handleCommand(conn, historyDB, line, arg, dst, isPrivate)
		}
	})

	return nil
}