quiz.go: fixed a bug destroying the ranklist

This commit is contained in:
Andreas Neue 2017-05-27 11:35:15 +02:00
parent acd39ed0af
commit 08ad03b4fa
2 changed files with 8 additions and 13 deletions

View File

@ -79,46 +79,37 @@ func markovRun() {
markovChain.Save(ModParams["markov-state-file"])
}
}()
}
func markovParseText(text string) string {
messageRegex := regexp.MustCompile(`<([^>]+)>`)
matches := messageRegex.FindAllStringSubmatch(text, -1)
for _, matches2 := range matches {
if strings.HasPrefix(matches2[1], "http") || strings.HasPrefix(matches2[1], "mailto") {
text = strings.Replace(text, matches2[0], "", -1)
} else if strings.HasPrefix(matches2[1], "@U") {
parts := strings.SplitN(matches2[1], "|", 2)
if len(parts) == 2 {
text = strings.Replace(text, matches2[0], "@"+parts[1], -1)
} else {
text = strings.Replace(text, matches2[0], "", -1)
}
} else if strings.HasPrefix(matches2[1], "@") {
text = strings.Replace(text, matches2[0], matches2[1], -1)
} else if strings.HasPrefix(matches2[1], "#") {
parts := strings.SplitN(matches2[1], "|", 2)
if len(parts) == 2 {
text = strings.Replace(text, matches2[0], "#"+parts[1], -1)
} else {
text = strings.Replace(text, matches2[0], "", -1)
}
}
}
text = strings.TrimSpace(text)
text = strings.Replace(text, "&lt;", "<", -1)
text = strings.Replace(text, "&gt;", ">", -1)
text = strings.Replace(text, "&amp;", "&", -1)
text = strings.Replace(text, ",", " ", -1)
return strings.ToLower(text)
}

View File

@ -102,20 +102,24 @@ func quizPrintRanklist(ranklist map[string]int) {
if len(ranklist) == 0 {
return
}
ranklistc := make(map[string]int, 0)
for k, v := range ranklist {
ranklistc[k] = v
}
SayCh <- fmt.Sprintf("%s\nAktueller Punktestand:", "*")
for {
maxk := ""
maxv := -1
if len(ranklist) == 0 {
if len(ranklistc) == 0 {
break
}
for k, v := range ranklist {
for k, v := range ranklistc {
if v > maxv {
maxv = v
maxk = k
}
}
delete(ranklist, maxk)
delete(ranklistc, maxk)
SayCh <- fmt.Sprintf("%s\n%s: %d", "*", maxk, maxv)
}
}