basic custom emoji support
MODIFY
ui/window.go
ui/window.go
@@ -3,6 +3,7 @@ package ui
import (
"bytes"
"fmt"
+ "regexp"
"strings"
"time"
@@ -32,6 +33,10 @@ const (
userInactiveTime = 10 * time.Second
)
+var (
+ emojiRegex = regexp.MustCompile(":.+:")
+)
+
// Window is basically the whole application, as it contains all the
// components and the necccessary global state.
type Window struct {
@@ -438,6 +443,10 @@ func NewWindow(doRestart chan bool, app *tview.Application, session *discordgo.S
window.messageInput.SetText("")
if len(messageToSend) != 0 {
+ messageToSend = codeBlockRegex.ReplaceAllStringFunc(messageToSend, func(input string) string {
+ return strings.Replace(input, ":", "\\:", -1)
+ })
+
if window.selectedGuild != nil {
guild, discordError := window.session.State.Guild(window.selectedGuild.ID)
if discordError == nil {
@@ -449,12 +458,19 @@ func NewWindow(doRestart chan bool, app *tview.Application, session *discordgo.S
}
}
+ messageToSend = emojiRegex.ReplaceAllStringFunc(messageToSend, func(match string) string {
+ matchStripped := strings.TrimPrefix(strings.TrimSuffix(match, ":"), ":")
+ for _, emoji := range guild.Emojis {
+ if emoji.Name == matchStripped {
+ return "<:" + emoji.Name + ":" + emoji.ID + ">"
}
}
- messageToSend = codeBlockRegex.ReplaceAllStringFunc(messageToSend, func(input string) string {
- return strings.Replace(input, ":", "\\:", -1)
+ return match
})
+ }
+ }
+
//Replace formatter characters and replace emoji codes.
messageToSend = discordemojimap.Replace(messageToSend)
messageToSend = strings.Replace(messageToSend, "\\:", ":", -1)

basic custom emoji support