Skip to content

Commit 0116d70

Browse files
authored
fix: stop displaying emotes used by other channels if emote text coll… (#21)
fix: stop displaying emotes used by other channels if emote text collides | other QOL changes
1 parent 97e75f5 commit 0116d70

File tree

6 files changed

+35
-15
lines changed

6 files changed

+35
-15
lines changed

emote/replacer.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ func intToRGB(i int) (byte, byte, byte) {
8989

9090
type EmoteStore interface {
9191
GetByTextAllChannels(text string) (Emote, bool)
92+
GetByText(channelID, text string) (Emote, bool)
9293
}
9394

9495
type Replacer struct {
@@ -137,12 +138,21 @@ func NewReplacer(httpClient *http.Client, store EmoteStore, enableGraphics bool,
137138
}
138139
}
139140

140-
func (i *Replacer) Replace(content string) (string, string, error) {
141+
func (i *Replacer) Replace(channelID, content string) (string, string, error) {
141142
words := strings.Split(content, " ")
142143

143144
var cmd strings.Builder
144145
for windex, word := range words {
145-
emote, isEmote := i.store.GetByTextAllChannels(word)
146+
var (
147+
emote Emote
148+
isEmote bool
149+
)
150+
151+
if channelID == "" {
152+
emote, isEmote = i.store.GetByTextAllChannels(word)
153+
} else {
154+
emote, isEmote = i.store.GetByText(channelID, word)
155+
}
146156

147157
if !isEmote {
148158
continue

emote/replacer_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func TestReplacer_Replace(t *testing.T) {
5050
return nil
5151
}
5252

53-
command, replacedText, err := replacer.Replace("Test Message with Kappa emote")
53+
command, replacedText, err := replacer.Replace("", "Test Message with Kappa emote")
5454
assert.Nil(t, err)
5555
assert.Equal(t, "\x1b_Gf=32,i=1,t=f,q=2,s=10,v=10;/path/to/kappa.png\x1b\\\x1b_Ga=p,i=1,p=1,q=2,U=1,r=1,c=2\x1b\\", command)
5656
assert.Equal(t, "Test Message with \x1b[38;2;0;0;1m\U0010eeee\U0010eeee\x1b[39m emote", replacedText)
@@ -81,7 +81,7 @@ func TestReplacer_Replace(t *testing.T) {
8181
return nil
8282
}
8383

84-
command, replacedText, err := replacer.Replace("Test Message with Kappa emote")
84+
command, replacedText, err := replacer.Replace("", "Test Message with Kappa emote")
8585
assert.Nil(t, err)
8686
assert.Equal(t, "", command)
8787
assert.Equal(t, "Test Message with Kappa emote", replacedText)
@@ -135,7 +135,7 @@ func TestReplacer_Replace(t *testing.T) {
135135
return nil
136136
}
137137

138-
command, replacedText, err := replacer.Replace("Test Message with Kappa emote")
138+
command, replacedText, err := replacer.Replace("", "Test Message with Kappa emote")
139139
assert.True(t, cached, "should call saveCached")
140140
assert.Nil(t, err)
141141
assert.Equal(t, "\x1b_Gf=32,i=1,t=f,q=2,s=28,v=28;L3BhdGgvdG8va2FwcGEucG5n\x1b\\\x1b_Ga=p,i=1,p=1,q=2,U=1,r=1,c=1\x1b\\", command)
@@ -182,3 +182,7 @@ func (m *mockEmoteStore) GetByTextAllChannels(text string) (Emote, bool) {
182182
emote, ok := m.emotes[text]
183183
return emote, ok
184184
}
185+
186+
func (m *mockEmoteStore) GetByText(_ string, text string) (Emote, bool) {
187+
return m.GetByTextAllChannels(text)
188+
}

ui/mainui/broadcast_tab.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,8 @@ func (t *broadcastTab) handleMessageSent(quickSend bool) tea.Cmd {
10511051
t.messageInput.SetValue("")
10521052
}
10531053

1054+
t.chatWindow.moveToBottom()
1055+
10541056
// Check if input is a command
10551057
if strings.HasPrefix(input, "/") {
10561058
// Get command name
@@ -1100,7 +1102,7 @@ func (t *broadcastTab) handleMessageSent(quickSend bool) tea.Cmd {
11001102
// Check if message is the same as the last message sent
11011103
// If so, append special character to bypass twitch duplicate message filter
11021104
if strings.EqualFold(input, t.lastMessageSent) {
1103-
input = input + string(duplicateBypass)
1105+
input = input + " " + string(duplicateBypass)
11041106
}
11051107

11061108
msg := &command.PrivateMessage{

ui/mainui/chat.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"github.com/charmbracelet/lipgloss"
1515
"github.com/julez-dev/chatuino/save"
1616
"github.com/julez-dev/chatuino/twitch/command"
17-
"github.com/lithammer/fuzzysearch/fuzzy"
1817
"github.com/muesli/reflow/wordwrap"
1918
"github.com/muesli/reflow/wrap"
2019
"github.com/rs/zerolog"
@@ -844,8 +843,13 @@ func (c *chatWindow) entryMatchesSearch(e *chatEntry) bool {
844843
return false
845844
}
846845

847-
search := c.searchInput.Value()
848-
if fuzzy.RankMatchNormalizedFold(search, cast.DisplayName) > 2 || fuzzy.RankMatchNormalizedFold(search, cast.Message) > 2 {
846+
// search := c.searchInput.Value()
847+
// if fuzzy.RankMatchFold(search, cast.DisplayName) > 5 || fuzzy.RankMatchFold(search, cast.Message) > 6 {
848+
// return true
849+
// }
850+
851+
search := strings.ToLower(c.searchInput.Value())
852+
if strings.Contains(strings.ToLower(cast.DisplayName), search) || strings.Contains(strings.ToLower(cast.Message), search) {
849853
return true
850854
}
851855

ui/mainui/root.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type EmoteStore interface {
4343
}
4444

4545
type EmoteReplacer interface {
46-
Replace(content string) (string, string, error)
46+
Replace(channelID, content string) (string, string, error)
4747
}
4848

4949
type APIClient interface {
@@ -1068,7 +1068,7 @@ func (r *Root) buildChatEventMessage(accountID string, tabID string, ircer twitc
10681068
switch ircMessage := ircer.(type) {
10691069
case *command.PrivateMessage:
10701070
channel = ircMessage.ChannelUserName
1071-
prepare, contentOverwrite, _ = r.emoteReplacer.Replace(ircMessage.Message)
1071+
prepare, contentOverwrite, _ = r.emoteReplacer.Replace(ircMessage.RoomID, ircMessage.Message)
10721072
io.WriteString(os.Stdout, prepare)
10731073
case *command.RoomState:
10741074
channel = ircMessage.ChannelUserName
@@ -1082,19 +1082,19 @@ func (r *Root) buildChatEventMessage(accountID string, tabID string, ircer twitc
10821082
channel = ircMessage.ChannelUserName
10831083
case *command.SubMessage:
10841084
channel = ircMessage.ChannelUserName
1085-
prepare, contentOverwrite, _ = r.emoteReplacer.Replace(ircMessage.Message)
1085+
prepare, contentOverwrite, _ = r.emoteReplacer.Replace(ircMessage.RoomID, ircMessage.Message)
10861086
io.WriteString(os.Stdout, prepare)
10871087
case *command.RaidMessage:
10881088
channel = ircMessage.ChannelUserName
10891089
case *command.SubGiftMessage:
10901090
channel = ircMessage.ChannelUserName
10911091
case *command.RitualMessage:
10921092
channel = ircMessage.ChannelUserName
1093-
prepare, contentOverwrite, _ = r.emoteReplacer.Replace(ircMessage.Message)
1093+
prepare, contentOverwrite, _ = r.emoteReplacer.Replace(ircMessage.RoomID, ircMessage.Message)
10941094
io.WriteString(os.Stdout, prepare)
10951095
case *command.AnnouncementMessage:
10961096
channel = ircMessage.ChannelUserName
1097-
prepare, contentOverwrite, _ = r.emoteReplacer.Replace(ircMessage.Message)
1097+
prepare, contentOverwrite, _ = r.emoteReplacer.Replace(ircMessage.RoomID, ircMessage.Message)
10981098
io.WriteString(os.Stdout, prepare)
10991099
}
11001100

ui/mainui/user_inspect.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func (u *userInspect) init(initialEvents []chatEventMessage) tea.Cmd {
132132
continue
133133
}
134134

135-
prepare, contentOverwrite, _ := u.emoteReplacer.Replace(loggedEntry.PrivateMessage.Message)
135+
prepare, contentOverwrite, _ := u.emoteReplacer.Replace(ttvResp.Data[0].ID, loggedEntry.PrivateMessage.Message)
136136
io.WriteString(os.Stdout, prepare)
137137

138138
fakeInitialEvent = append(fakeInitialEvent, chatEventMessage{

0 commit comments

Comments
 (0)