예제 #1
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
}
예제 #2
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
}