Browse Source

Add new syntax for giving votes

Toni Fadjukoff 6 years ago
parent
commit
fb7c68b763
2 changed files with 5 additions and 2 deletions
  1. 1 1
      bot.go
  2. 4 1
      bot_test.go

+ 1 - 1
bot.go View File

@@ -167,7 +167,7 @@ func parseScore(line string) string {
167 167
 	if stars.MatchString(score) {
168 168
 		return fmt.Sprintf("%d", len(score))
169 169
 	}
170
-	imageStars, _ := regexp.Compile("^(\\[\\[Image:[01]\\.png\\]\\]){5}$")
170
+	imageStars, _ := regexp.Compile("^(\\[\\[Image:[01]\\.png\\]\\]){1,5}$")
171 171
 	if imageStars.MatchString(score) {
172 172
 		return fmt.Sprintf("%d", strings.Count(score, "1"))
173 173
 	}

+ 4 - 1
bot_test.go View File

@@ -7,7 +7,10 @@ func testParseScore(t *testing.T) {
7 7
 	if s != "3" {
8 8
 		t.Fail()
9 9
 	}
10
-
10
+	s = parseScore("[[Image:1.png]][[Image:1.png]]")
11
+	if s != "2" {
12
+		t.Fail()
13
+	}
11 14
 	s = parseScore("{{Rating|3|5}}")
12 15
 	if s != "3" {
13 16
 		t.Fail()