Add emoji support
This commit is contained in:
parent
7555f594f0
commit
25b3ccf08d
1511
config/emoji.go
Normal file
1511
config/emoji.go
Normal file
File diff suppressed because it is too large
Load Diff
@ -3,10 +3,13 @@ package service
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/nlopes/slack"
|
"github.com/nlopes/slack"
|
||||||
|
|
||||||
|
"github.com/erroneousboat/slack-term/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -291,7 +294,7 @@ func (s *SlackService) CreateMessage(message slack.Message) []string {
|
|||||||
"[%s] <%s> %s",
|
"[%s] <%s> %s",
|
||||||
time.Unix(intTime, 0).Format("15:04"),
|
time.Unix(intTime, 0).Format("15:04"),
|
||||||
name,
|
name,
|
||||||
message.Text,
|
parseEmoji(message.Text),
|
||||||
)
|
)
|
||||||
|
|
||||||
msgs = append(msgs, msg)
|
msgs = append(msgs, msg)
|
||||||
@ -357,7 +360,7 @@ func (s *SlackService) CreateMessageFromMessageEvent(message *slack.MessageEvent
|
|||||||
"[%s] <%s> %s",
|
"[%s] <%s> %s",
|
||||||
time.Unix(intTime, 0).Format("15:04"),
|
time.Unix(intTime, 0).Format("15:04"),
|
||||||
name,
|
name,
|
||||||
message.Text,
|
parseEmoji(message.Text),
|
||||||
)
|
)
|
||||||
|
|
||||||
msgs = append(msgs, msg)
|
msgs = append(msgs, msg)
|
||||||
@ -391,3 +394,19 @@ func createMessageFromAttachments(atts []slack.Attachment) []string {
|
|||||||
|
|
||||||
return msgs
|
return msgs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// parseEmoji will try to find emoji placeholders in the message
|
||||||
|
// string and replace them with the correct unicode equivalent
|
||||||
|
func parseEmoji(msg string) string {
|
||||||
|
r := regexp.MustCompile("(:\\w+:)")
|
||||||
|
|
||||||
|
return r.ReplaceAllStringFunc(
|
||||||
|
msg, func(str string) string {
|
||||||
|
code, ok := config.EmojiCodemap[str]
|
||||||
|
if !ok {
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
return code
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user