Esempio n. 1
0
func handleRotate(state State, msg message.MsgPrivate) bool {
	if !strings.HasPrefix(strings.ToLower(msg.Msg), "rotate") {
		return false
	}
	state.ResponseChannel <- message.MsgSend{msg.Response(), bstrings.RotateString(msg.Msg[6:])}
	return true
}
Esempio n. 2
0
func handleHelp(state State, msg message.MsgPrivate) bool {
	if strings.ToLower(msg.Msg) != "gobot: help" {
		return false
	}
	state.ResponseChannel <- message.MsgSend{msg.Response(), state.Conf.Help}
	return true
}
Esempio n. 3
0
func handleTimezoneConversion(state State, msg message.MsgPrivate) bool {
	ts, err := parseTimezoneQuery(msg.Msg)
	if err != nil {
		return false
	}
	state.ResponseChannel <- message.MsgSend{msg.Response(), ts.String()}
	return true
}
Esempio n. 4
0
func handleTroll(state State, msg message.MsgPrivate) bool {
	if !strings.HasPrefix(strings.ToLower(msg.Msg), "troll") {
		return false
	}
	winners := []string{msg.Nick()}
	resp := formatWinners(winners, state.Conf)
	state.ResponseChannel <- message.MsgSend{msg.Response(), resp}
	return true
}
Esempio n. 5
0
func handleDodo(state State, msg message.MsgPrivate) bool {
	if !strings.Contains(strings.ToLower(msg.Msg), "dodo") {
		return false
	}
	zStr := strings.Repeat("Zz", rand.Intn(25))
	res := bstrings.ColorStringSlice(bstrings.ShuffleString(zStr))
	nick := getNickInMessage(state.Db, msg.Msg)
	state.ResponseChannel <- message.MsgSend{msg.Response(), fmt.Sprintf("%s%s", nick, res)}
	return true
}
Esempio n. 6
0
func placeBet(state State, nick string, msg message.MsgPrivate, ts time.Time, isAdmin bool) {
	err := bet.AddUserBet(state.Db, nick, ts, isAdmin)
	if err == nil {
		ts_str := fmt.Sprintf("Za dude %s placed bet for %s", nick, ts.Format(time.RFC1123Z))
		state.ResponseChannel <- message.MsgSend{msg.Response(), ts_str}
	} else {
		ts_str := fmt.Sprintf("Hey %s, %s", nick, err)
		state.ResponseChannel <- message.MsgSend{msg.Response(), ts_str}
	}
}
Esempio n. 7
0
func handleReset(state State, msg message.MsgPrivate) bool {
	if strings.ToLower(msg.Msg) != "reset" {
		return false
	}
	if strings.ToLower(msg.User) != state.Conf.Admin {
		return false
	}
	bet.ResetBet(state.Db)
	state.ResponseChannel <- message.MsgSend{msg.Response(), "I have reset the bet, master."}
	return true
}
Esempio n. 8
0
func handleBetSpecificTimeZone(state State, msg message.MsgPrivate) bool {
	if !strings.HasPrefix(strings.ToLower(msg.Msg), "bet") {
		return false
	}
	location, err := time.LoadLocation(msg.Msg[4:])
	if err != nil {
		state.ResponseChannel <- message.MsgSend{msg.Response(), "Invalid timezone dude"}
	} else {
		printBet(state, location, msg)
	}
	return true
}
Esempio n. 9
0
func printSpecificBet(state State, betId int, location *time.Location, msg message.MsgPrivate) {
	bets := bet.GetUserBets(state.Db, betId)
	nicks := make([]string, len(bets))
	for _, bet := range bets {
		nicks = append(nicks, bet.String())
	}
	maxSize := getMaxNickLength(nicks)
	for _, userBet := range bets {
		resp := fmt.Sprintf("%*s %s", maxSize, userBet.Nick, userBet.Time.In(location))
		state.ResponseChannel <- message.MsgSend{msg.Response(), resp}
	}
}
Esempio n. 10
0
func handlePutf8(state State, msg message.MsgPrivate) bool {
	if !strings.Contains(strings.ToLower(msg.Msg), "putf8") {
		return false
	}
	numChars := rand.Intn(25)
	res := make([]string, numChars)
	for i := 0; i < numChars; i++ {
		res[i] = bstrings.ColorString(bstrings.GetRandUtf8())
	}
	nick := getNickInMessage(state.Db, msg.Msg)
	state.ResponseChannel <- message.MsgSend{msg.Response(), fmt.Sprintf("%s%s", nick, strings.Join(res, " "))}
	return true
}
Esempio n. 11
0
func handleMeteo(state State, msg message.MsgPrivate) bool {
	lowerMsg := strings.ToLower(msg.Msg)
	if lowerMsg == "meteo" || lowerMsg == "météo" {
		weather, err := meteo.FetchWeatherFromUrl(state.Conf.Meteo.Url)
		if err != nil {
			log.Printf("Erro on fetch weather : %q", err)
			return true
		}
		log.Printf("Fetched %q", weather)
		state.ResponseChannel <- message.MsgSend{msg.Response(), strings.Join(weather, "|")}
		return true
	}
	return false
}
Esempio n. 12
0
func handleScores(state State, msg message.MsgPrivate) bool {
	if strings.ToLower(msg.Msg) != "scores" {
		return false
	}
	scores := bet.GetScores(state.Db)
	nicks := make([]string, len(scores))
	for _, score := range scores {
		nicks = append(nicks, score.String())
	}
	maxSize := getMaxNickLength(nicks)

	for _, v := range scores {
		resp := fmt.Sprintf("%*s %d", maxSize, v.Nick, v.Score)
		state.ResponseChannel <- message.MsgSend{msg.Response(), resp}
	}
	return true
}
Esempio n. 13
0
func handleTrigger(state State, msg message.MsgPrivate, trigger Trigger) bool {
	lowerMsg := strings.ToLower(msg.Msg)
	lowerMsg = strings.Map(bstrings.KeepLettersAndSpace, lowerMsg)
	if !bstrings.TriggerIn(trigger.Words, lowerMsg) {
		return false
	}
	resp := ""
	nick := getNickInMessage(state.Db, msg.Msg)
	resp = pickMessage(trigger)
	lines := strings.Split(resp, "\n")
	for _, l := range lines {
		if l != "" {
			state.ResponseChannel <- message.MsgSend{msg.Response(), fmt.Sprintf("%s%s", nick, l)}
		}
	}
	return true
}
Esempio n. 14
0
func handleBsTraining(state State, msg message.MsgPrivate) bool {
	lowerMsg := strings.ToLower(msg.Msg)
	if lowerMsg == "bsreload" {
		state.BsQueryChannel <- bsmeter.BsQuery{IsReload: true}
		return true
	}
	if !strings.HasPrefix(lowerMsg, "bs") && !strings.HasPrefix(lowerMsg, "nobs") {
		return false
	}
	bs := strings.HasPrefix(lowerMsg, "bs")
	urls := html.ExtractUrls(msg.Msg)
	if len(urls) == 0 {
		state.BsQueryChannel <- bsmeter.BsQuery{
			Phrase:     removeFirstWord(lowerMsg),
			IsTraining: true, Bs: bs, Channel: msg.Response()}
	} else {
		state.BsQueryChannel <- bsmeter.BsQuery{Urls: urls,
			IsTraining: true, Bs: bs, Channel: msg.Response()}
	}
	return true
}
Esempio n. 15
0
func handleBsRequest(state State, msg message.MsgPrivate) bool {
	lowerMsg := strings.ToLower(msg.Msg)
	bsQuery := bsmeter.BsQuery{Channel: msg.Response()}
	hasBsQuery := strings.HasPrefix(lowerMsg, "isbs")
	hasHttp := strings.Contains(lowerMsg, "http")
	if hasHttp {
		urls := html.ExtractUrls(msg.Msg)
		bsQuery.Urls = urls
	}
	if hasBsQuery {
		phrase := removeFirstWord(lowerMsg)
		for _, url := range bsQuery.Urls {
			phrase = strings.Replace(phrase, url, "", -1)
		}
		bsQuery.Phrase = phrase
	}
	if hasHttp || hasBsQuery {
		state.BsQueryChannel <- bsQuery
		return true
	}
	return false
}
Esempio n. 16
0
func handleMetapi(state State, msg message.MsgPrivate) bool {
	log.Printf("Check %s", msg.Msg)
	if !strings.HasPrefix(strings.ToLower(msg.Msg), "metapi") {
		return false
	}
	log.Printf("Passed for %s", msg.Msg)
	num, err := strconv.ParseInt(msg.Msg[7:], 10, 64)
	if err != nil {
		state.ResponseChannel <- message.MsgSend{msg.Response(), fmt.Sprintf("Expect an int32 to search, error was %q", err)}
		return true
	} else {
		state.ResponseChannel <- message.MsgSend{msg.Response(), "Launching big real data time calculation on the claoud"}
		state.PiQueryChannel <- metapi.PiQuery{num, msg.Response()}
	}
	return true
}
Esempio n. 17
0
func closeBet(state State, msg message.MsgPrivate, ts time.Time) {
	winners := bet.CloseBet(state.Db, ts)
	resp := formatWinners(winners, state.Conf)
	state.ResponseChannel <- message.MsgSend{msg.Response(), resp}
}