Skip to content

Commit dfce076

Browse files
committed
Add option to show emojis by converting their string/aliases to unicode
1 parent 753f26e commit dfce076

File tree

9 files changed

+2267
-0
lines changed

9 files changed

+2267
-0
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ require (
77
github.com/google/gops v0.3.27
88
github.com/grokify/html-strip-tags-go v0.0.1
99
github.com/hashicorp/golang-lru v0.6.0
10+
github.com/kenshaw/emoji v0.3.3
1011
github.com/matterbridge/logrus-prefixed-formatter v0.5.3-0.20200523233437-d971309a77ba
1112
github.com/matterbridge/matterclient v0.0.0-20230909230346-007c5c33c54c
1213
github.com/mattermost/mattermost-server/v6 v6.7.2

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,8 @@ github.com/kataras/neffos v0.0.14/go.mod h1:8lqADm8PnbeFfL7CLXh1WHw53dG27MC3pgi2
840840
github.com/kataras/pio v0.0.2/go.mod h1:hAoW0t9UmXi4R5Oyq5Z4irTbaTsOemSrDGUtaTl7Dro=
841841
github.com/kataras/sitemap v0.0.5/go.mod h1:KY2eugMKiPwsJgx7+U103YZehfvNGOXURubcGyk0Bz8=
842842
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
843+
github.com/kenshaw/emoji v0.3.3 h1:hnCZ1UMxgw81UBYqMgbO65s+PbzBT+DDAM7W3nGdpgI=
844+
github.com/kenshaw/emoji v0.3.3/go.mod h1:UHZHpun22ziHK9+1SuVYWq+rdFzQJLy5xtNC3k6Qbyw=
843845
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
844846
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
845847
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=

matterircd.toml.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ ShortenRepliesTo = 0
126126
Unicode = false
127127
# Disable showing reactions
128128
HideReactions = false
129+
# Disable converting Mattermost markdown of text emphasis to IRC text emphasis
130+
#DisableIRCEmphasis
131+
# Disable converting emoji strings/aliases to their unicode equivalent
132+
#DisableEmoji = true
129133

130134
#Only join direct/group messages when someone talks. This stops from cluttering your
131135
#irc client with lots of windows.

mm-go-irckit/userbridge.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/42wim/matterircd/bridge/slack"
2121
"github.com/alecthomas/chroma/v2/quick"
2222
"github.com/davecgh/go-spew/spew"
23+
"github.com/kenshaw/emoji"
2324
"github.com/mattermost/mattermost-server/v6/model"
2425
"github.com/muesli/reflow/wordwrap"
2526
"github.com/sorcix/irc"
@@ -169,6 +170,10 @@ func (u *User) handleDirectMessageEvent(event *bridge.DirectMessageEvent) {
169170
text = markdown2irc(text)
170171
}
171172

173+
if !u.v.GetBool(u.br.Protocol()+".disableemoji") && !codeBlockBackTick && !codeBlockTilde { //nolint:goconst
174+
text = emoji.ReplaceAliases(text)
175+
}
176+
172177
if showContext {
173178
text = prefix + text + suffix
174179
}
@@ -325,6 +330,10 @@ func (u *User) handleChannelMessageEvent(event *bridge.ChannelMessageEvent) {
325330
text = markdown2irc(text)
326331
}
327332

333+
if !u.v.GetBool(u.br.Protocol()+".disableemoji") && !codeBlockBackTick && !codeBlockTilde {
334+
text = emoji.ReplaceAliases(text)
335+
}
336+
328337
if showContext {
329338
text = prefix + text + suffix
330339
}
@@ -458,6 +467,13 @@ func (u *User) handleReactionEvent(event interface{}) {
458467
return
459468
}
460469

470+
if !u.v.GetBool(u.br.Protocol() + ".disableemoji") {
471+
reactionEmoji := emoji.FromAlias(reaction)
472+
if reactionEmoji != nil {
473+
reaction = fmt.Sprintf("%s", reactionEmoji)
474+
}
475+
}
476+
461477
if channelType == "D" {
462478
e := &bridge.DirectMessageEvent{
463479
Text: "\x1d" + text + reaction + "\x1d" + message,

vendor/github.com/kenshaw/emoji/LICENSE

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/kenshaw/emoji/README.md

Lines changed: 68 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)