Custom emoji's are now rendered in markdown link format
MODIFY
ui/chatview.go
ui/chatview.go
@@ -31,7 +31,7 @@ const dashCharacter = "\u2500"
var (
successiveCustomEmojiRegex = regexp.MustCompile("<a?:.+?:\\d+(><)a?:.+?:\\d+>")
- customEmojiRegex = regexp.MustCompile("(?sm)(.?)<a?:.+?:(\\d+)>(.?)")
+ customEmojiRegex = regexp.MustCompile("(?sm)(.?)<(a?):(.+?):(\\d+)>(.?)")
codeBlockRegex = regexp.MustCompile("(?sm)(^|.)?(\x60\x60\x60(.*?)?\n(.+?)\x60\x60\x60)($|.)")
colorRegex = regexp.MustCompile("\\[#.{6}\\]")
channelMentionRegex = regexp.MustCompile(`<#\d*>`)
@@ -676,12 +676,16 @@ func parseCustomEmojis(text string) string {
customEmojiMatches := customEmojiRegex.FindAllStringSubmatch(messageText, -1)
for _, match := range customEmojiMatches {
- url := "https://cdn.discordapp.com/emojis/" + match[2]
+ custom_emoji_code := match[3]
+ if len(match[2]) > 0 {
+ custom_emoji_code = "a:" + custom_emoji_code
+ }
+ url := tviewutil.Escape("[" + custom_emoji_code + "](https://cdn.discordapp.com/emojis/" + match[4] + ")")
if match[1] != "" && match[1] != "\n" {
url = match[1] + "\n" + url
}
- if match[3] != "" && match[3] != "\n" {
- url = url + "\n" + match[3]
+ if match[5] != "" && match[5] != "\n" {
+ url = url + "\n" + match[5]
}
messageText = strings.Replace(messageText, match[0], url, 1)
}

MODIFY
ui/chatview_test.go
ui/chatview_test.go
@@ -375,7 +375,7 @@ func TestChatView_formatMessageText(t *testing.T) {
ID: "OwO",
Content: "<:owo:123>",
},
- want: "https://cdn.discordapp.com/emojis/123",
+ want: "[owo[](https://cdn.discordapp.com/emojis/123)",
chatView: defaultChatView,
}, {
name: "single animated custom emoji",
@@ -383,7 +383,7 @@ func TestChatView_formatMessageText(t *testing.T) {
ID: "OwO",
Content: "<a:owo:123>",
},
- want: "https://cdn.discordapp.com/emojis/123",
+ want: "[a:owo[](https://cdn.discordapp.com/emojis/123)",
chatView: defaultChatView,
}, {
//FIXME Remove space, it's useless
@@ -392,7 +392,7 @@ func TestChatView_formatMessageText(t *testing.T) {
ID: "OwO",
Content: "<:owo:123><:owo:123>",
},
- want: "https://cdn.discordapp.com/emojis/123\n https://cdn.discordapp.com/emojis/123",
+ want: "[owo[](https://cdn.discordapp.com/emojis/123)\n [owo[](https://cdn.discordapp.com/emojis/123)",
chatView: defaultChatView,
}, {
//FIXME Remove space, it's useless
@@ -401,7 +401,7 @@ func TestChatView_formatMessageText(t *testing.T) {
ID: "OwO",
Content: "<:owo:123> <:owo:123>",
},
- want: "https://cdn.discordapp.com/emojis/123\n https://cdn.discordapp.com/emojis/123",
+ want: "[owo[](https://cdn.discordapp.com/emojis/123)\n [owo[](https://cdn.discordapp.com/emojis/123)",
chatView: defaultChatView,
}, {
//FIXME Remove space, it's useless
@@ -410,7 +410,7 @@ func TestChatView_formatMessageText(t *testing.T) {
ID: "OwO",
Content: "<:owo:123><:owo:124><:owo:125><:owo:126>",
},
- want: "https://cdn.discordapp.com/emojis/123\n https://cdn.discordapp.com/emojis/124\n https://cdn.discordapp.com/emojis/125\n https://cdn.discordapp.com/emojis/126",
+ want: "[owo[](https://cdn.discordapp.com/emojis/123)\n [owo[](https://cdn.discordapp.com/emojis/124)\n [owo[](https://cdn.discordapp.com/emojis/125)\n [owo[](https://cdn.discordapp.com/emojis/126)",
chatView: defaultChatView,
}, {
//FIXME Remove space, it's useless
@@ -419,7 +419,7 @@ func TestChatView_formatMessageText(t *testing.T) {
ID: "OwO",
Content: "<:owo:123> <:owo:124> <:owo:125> <:owo:126>",
},
- want: "https://cdn.discordapp.com/emojis/123\n https://cdn.discordapp.com/emojis/124\n https://cdn.discordapp.com/emojis/125\n https://cdn.discordapp.com/emojis/126",
+ want: "[owo[](https://cdn.discordapp.com/emojis/123)\n [owo[](https://cdn.discordapp.com/emojis/124)\n [owo[](https://cdn.discordapp.com/emojis/125)\n [owo[](https://cdn.discordapp.com/emojis/126)",
chatView: defaultChatView,
}, {
//FIXME Remove spaces behind prefix and suffix of emoji
@@ -428,7 +428,7 @@ func TestChatView_formatMessageText(t *testing.T) {
ID: "OwO",
Content: "Look, <:owo:123> what's this?",
},
- want: "Look, \nhttps://cdn.discordapp.com/emojis/123\n what's this?",
+ want: "Look, \n[owo[](https://cdn.discordapp.com/emojis/123)\n what's this?",
chatView: defaultChatView,
}, {
//FIXME Remove spaces behind prefix and suffix of emoji
@@ -437,7 +437,7 @@ func TestChatView_formatMessageText(t *testing.T) {
ID: "OwO",
Content: "Look, <:owo:123> <:owo:123> what's this?",
},
- want: "Look, \nhttps://cdn.discordapp.com/emojis/123\n https://cdn.discordapp.com/emojis/123\n what's this?",
+ want: "Look, \n[owo[](https://cdn.discordapp.com/emojis/123)\n [owo[](https://cdn.discordapp.com/emojis/123)\n what's this?",
chatView: defaultChatView,
}, {
//FIXME Remove spaces behind prefix and suffix of emoji
@@ -446,7 +446,15 @@ func TestChatView_formatMessageText(t *testing.T) {
ID: "OwO",
Content: "Look, <:owo:123><:owo:123> what's this?",
},
- want: "Look, \nhttps://cdn.discordapp.com/emojis/123\n https://cdn.discordapp.com/emojis/123\n what's this?",
+ want: "Look, \n[owo[](https://cdn.discordapp.com/emojis/123)\n [owo[](https://cdn.discordapp.com/emojis/123)\n what's this?",
+ chatView: defaultChatView,
+ }, {
+ name: "message with custom animated emoji",
+ input: &discordgo.Message{
+ ID: "OwO",
+ Content: "Hello <a:owo:123>",
+ },
+ want: "Hello \n[a:owo[](https://cdn.discordapp.com/emojis/123)",
chatView: defaultChatView,
},
}

Custom emoji's are now rendered in markdown link format