quiz.go: fixed a bug destroying the ranklist
This commit is contained in:
parent
acd39ed0af
commit
08ad03b4fa
|
@ -79,46 +79,37 @@ func markovRun() {
|
||||||
markovChain.Save(ModParams["markov-state-file"])
|
markovChain.Save(ModParams["markov-state-file"])
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func markovParseText(text string) string {
|
func markovParseText(text string) string {
|
||||||
messageRegex := regexp.MustCompile(`<([^>]+)>`)
|
messageRegex := regexp.MustCompile(`<([^>]+)>`)
|
||||||
matches := messageRegex.FindAllStringSubmatch(text, -1)
|
matches := messageRegex.FindAllStringSubmatch(text, -1)
|
||||||
for _, matches2 := range matches {
|
for _, matches2 := range matches {
|
||||||
|
|
||||||
if strings.HasPrefix(matches2[1], "http") || strings.HasPrefix(matches2[1], "mailto") {
|
if strings.HasPrefix(matches2[1], "http") || strings.HasPrefix(matches2[1], "mailto") {
|
||||||
text = strings.Replace(text, matches2[0], "", -1)
|
text = strings.Replace(text, matches2[0], "", -1)
|
||||||
|
|
||||||
} else if strings.HasPrefix(matches2[1], "@U") {
|
} else if strings.HasPrefix(matches2[1], "@U") {
|
||||||
parts := strings.SplitN(matches2[1], "|", 2)
|
parts := strings.SplitN(matches2[1], "|", 2)
|
||||||
|
|
||||||
if len(parts) == 2 {
|
if len(parts) == 2 {
|
||||||
text = strings.Replace(text, matches2[0], "@"+parts[1], -1)
|
text = strings.Replace(text, matches2[0], "@"+parts[1], -1)
|
||||||
} else {
|
} else {
|
||||||
text = strings.Replace(text, matches2[0], "", -1)
|
text = strings.Replace(text, matches2[0], "", -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if strings.HasPrefix(matches2[1], "@") {
|
} else if strings.HasPrefix(matches2[1], "@") {
|
||||||
text = strings.Replace(text, matches2[0], matches2[1], -1)
|
text = strings.Replace(text, matches2[0], matches2[1], -1)
|
||||||
|
|
||||||
} else if strings.HasPrefix(matches2[1], "#") {
|
} else if strings.HasPrefix(matches2[1], "#") {
|
||||||
parts := strings.SplitN(matches2[1], "|", 2)
|
parts := strings.SplitN(matches2[1], "|", 2)
|
||||||
|
|
||||||
if len(parts) == 2 {
|
if len(parts) == 2 {
|
||||||
text = strings.Replace(text, matches2[0], "#"+parts[1], -1)
|
text = strings.Replace(text, matches2[0], "#"+parts[1], -1)
|
||||||
} else {
|
} else {
|
||||||
text = strings.Replace(text, matches2[0], "", -1)
|
text = strings.Replace(text, matches2[0], "", -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
text = strings.TrimSpace(text)
|
text = strings.TrimSpace(text)
|
||||||
|
|
||||||
text = strings.Replace(text, "<", "<", -1)
|
text = strings.Replace(text, "<", "<", -1)
|
||||||
text = strings.Replace(text, ">", ">", -1)
|
text = strings.Replace(text, ">", ">", -1)
|
||||||
text = strings.Replace(text, "&", "&", -1)
|
text = strings.Replace(text, "&", "&", -1)
|
||||||
|
text = strings.Replace(text, ",", " ", -1)
|
||||||
|
|
||||||
return strings.ToLower(text)
|
return strings.ToLower(text)
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,20 +102,24 @@ func quizPrintRanklist(ranklist map[string]int) {
|
||||||
if len(ranklist) == 0 {
|
if len(ranklist) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
ranklistc := make(map[string]int, 0)
|
||||||
|
for k, v := range ranklist {
|
||||||
|
ranklistc[k] = v
|
||||||
|
}
|
||||||
SayCh <- fmt.Sprintf("%s\nAktueller Punktestand:", "*")
|
SayCh <- fmt.Sprintf("%s\nAktueller Punktestand:", "*")
|
||||||
for {
|
for {
|
||||||
maxk := ""
|
maxk := ""
|
||||||
maxv := -1
|
maxv := -1
|
||||||
if len(ranklist) == 0 {
|
if len(ranklistc) == 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
for k, v := range ranklist {
|
for k, v := range ranklistc {
|
||||||
if v > maxv {
|
if v > maxv {
|
||||||
maxv = v
|
maxv = v
|
||||||
maxk = k
|
maxk = k
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete(ranklist, maxk)
|
delete(ranklistc, maxk)
|
||||||
SayCh <- fmt.Sprintf("%s\n%s: %d", "*", maxk, maxv)
|
SayCh <- fmt.Sprintf("%s\n%s: %d", "*", maxk, maxv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue