Make emoji code parsing more lax
MODIFY
ui/window.go
ui/window.go
@@ -8,6 +8,7 @@ import (
"log"
"strings"
"time"
+ "unicode"
"github.com/Bios-Marcel/discordemojimap"
"github.com/Bios-Marcel/goclipimg"
@@ -1251,7 +1252,6 @@ func (window *Window) prepareMessage(targetChannel *discordgo.Channel, inputText
}
func emojiSequenceIndexes(runes []rune) []int {
- //TODO Exclamation mark
var sequencesBackwards []int
for i := len(runes) - 1; i >= 0; i-- {
if runes[i] == ':' {
@@ -1266,20 +1266,13 @@ func emojiSequenceIndexes(runes []rune) []int {
} else {
break
}
- } else {
- //Valid chars for emoji names
- if !((char >= 'A' && char <= 'Z') || (char >= 'a' && char <= 'z') || (char >= '0' && char <= '9') || char == '_') {
- //If invalid, jump out of loop
- //Exception for exclamation marks
- if !(char == '!' && j != 0 && runes[j-1] == ':') {
+ } else if unicode.IsSpace(char) {
i = j
break
}
}
}
}
- }
- }
return sequencesBackwards
}

MODIFY
ui/window_test.go
ui/window_test.go
@@ -39,41 +39,47 @@ func Test_emojiSequenceIndexes(t *testing.T) {
},
want: nil,
}, {
- name: "",
+ name: "single valid standalone emoji sequence",
args: args{
runes: []rune(":test:"),
},
want: []int{0, 5},
}, {
- name: "",
+ name: "two valid emoji sequences right next to eachother",
args: args{
runes: []rune(":test::lol:"),
},
want: []int{6, 10, 0, 5},
}, {
- name: "",
+ name: "two valid emoji sequences with single unnecessary double colons inbetween",
args: args{
runes: []rune(":test:::lol:"),
},
want: []int{7, 11, 0, 5},
}, {
- name: "",
+ name: "two valid emoji sequences with even amount of double colons inbetween",
args: args{
runes: []rune("::test:::lol:"),
},
want: []int{8, 12, 1, 6},
}, {
- name: "",
+ name: "two valid emoji sequences with uneven amount of double colons inbetween",
args: args{
runes: []rune("::test::::lol:"),
},
want: []int{9, 13, 1, 6},
}, {
- name: "",
+ name: "one emoji sequence in the end and the beginning",
args: args{
runes: []rune(":test: Hello yeah :lol:"),
},
want: []int{18, 22, 0, 5},
+ }, {
+ name: "emoji sequences with space, therefore invalid",
+ args: args{
+ runes: []rune(":test :"),
+ },
+ want: nil,
},
}
for _, tt := range tests {

Make emoji code parsing more lax