Example #1
0
func StartTicker(seconds int) {
	if tickerExists(&seconds) {
		logger.Debug("Not starting another " + string(seconds) + "s ticker.")
		return
	}
	Tickers[seconds] = &Ticker{
		duration: &seconds,
		ticker:   time.NewTicker(time.Duration(seconds) * time.Second),
		quit:     make(chan struct{}),
	}
	go func() {
		for {
			select {
			case <-Tickers[seconds].ticker.C:
				for _, event := range Tickers[seconds].events {
					event.callback()
				}
			case <-Tickers[seconds].quit:
				Tickers[seconds].ticker.Stop()
				logger.Debug("Stopped " + string(seconds) + "s ticker.")
				return
			}
		}
	}()
}
Example #2
0
func StopTicker(ticker int) {
	if !tickerExists(&ticker) {
		logger.Debug("Tried to stop non-existant " + string(ticker) + "s ticker.")
		return
	}
	close(Tickers[ticker].quit)
	logger.Debug("Stopped " + string(ticker) + "s ticker.")
}
Example #3
0
File: web.go Project: Kaioshi/Kari
func GetTitle(rawuri string) string {
	var index int
	ext := rawuri[strings.LastIndex(rawuri, "//")+2:]
	if index = strings.LastIndex(ext, "/"); index > 0 {
		ext = ext[index+1:]
		if index = strings.Index(ext, "."); index > -1 {
			ext = ext[index+1:]
			allow := []string{"htm", "html", "asp", "aspx", "php", "php3", "php5"}
			if !lib.HasElementString(allow, ext) {
				logger.Debug(fmt.Sprintf("[web.GetTitle()] Not an OK file extension: %s -> %s",
					rawuri, ext))
				return ""
			}
		}
	}
	body, err := Get(&rawuri)
	if err != "" {
		return ""
	}
	r, regErr := regexp.Compile("<title?[^>]+>([^<]+)<\\/title>")
	if regErr != nil {
		logger.Error("[web.GetTitle()] Couldn't compile regex title regex")
		return ""
	}
	if title := r.FindString(string(body)); title != "" {
		rooturl := rawuri[strings.Index(rawuri, "//")+2:]
		if index = strings.Index(rooturl, "/"); index > -1 {
			rooturl = rooturl[:index]
		}
		return fmt.Sprintf("%s ~ %s", html.UnescapeString(lib.StripHtml(title)), rooturl)
	}
	return ""
}
Example #4
0
func RandPreposition() string {
	prep := string(*lib.RandSelectBytes(getFileContents("prepositions")))
	if prep == "" {
		logger.Debug("Had to re-fetch Preposition")
		prep = RandPreposition()
	}
	return prep
}
Example #5
0
func RandPronoun() string {
	pro := string(*lib.RandSelectBytes(getFileContents("pronouns")))
	if pro == "" {
		logger.Debug("Had to re-fetch Pronoun")
		pro = RandPronoun()
	}
	return pro
}
Example #6
0
func RandAdverb() string {
	adv := string(*lib.RandSelectBytes(getFileContents("adverbs")))
	if adv == "" {
		logger.Debug("Had to re-fetch Adverb")
		adv = RandAdverb()
	}
	return adv
}
Example #7
0
func RandAdjective() string {
	adj := string(*lib.RandSelectBytes(getFileContents("adjectives")))
	if adj == "" {
		logger.Debug("Had to re-fetch Adjective")
		adj = RandAdjective()
	}
	return adj
}
Example #8
0
func RandNoun() string {
	noun := string(*lib.RandSelectBytes(getFileContents("nouns")))
	if noun == "" {
		logger.Debug("Had to re-fetch Noun")
		noun = RandNoun()
	}
	return noun
}
Example #9
0
func RandVerbing() string {
	verb := string(*lib.RandSelectBytes(getFileContents("verbs")))
	if verb == "" {
		logger.Debug("Had to re-fetch Verb[ing]")
		verb = RandVerbing()
	}
	return strings.Split(verb, " ")[3]
}
Example #10
0
func RandVerb() string {
	verb := string(*lib.RandSelectBytes(getFileContents("verbs")))
	if verb == "" {
		logger.Debug("Had to re-fetch Verb")
		verb = RandVerb()
	}
	return verb[0:strings.Index(verb, " ")]
}