Skip to content

Commit

Permalink
Handle empty action messages (#169)
Browse files Browse the repository at this point in the history
* handle empty action messages

* add a test for empty action messages

Co-authored-by: Rasmus Karlsson <[email protected]>
  • Loading branch information
gempir and pajlada authored Nov 22, 2021
1 parent 61d050b commit 5da4523
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion message.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,12 @@ func parsePrivateMessage(message *ircMessage) Message {

text := privateMessage.Message
if strings.HasPrefix(text, "\u0001ACTION") && strings.HasSuffix(text, "\u0001") {
privateMessage.Message = text[8 : len(text)-1]
privateMessage.Action = true
if len(text) == 8 {
privateMessage.Message = ""
} else {
privateMessage.Message = text[8 : len(text)-1]
}
}

privateMessage.Emotes = parseEmotes(message.Tags["emotes"], privateMessage.Message)
Expand Down
10 changes: 10 additions & 0 deletions message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ import (
"testing"
)

func TestCanPraseBadActionMessageWithoutPanic(t *testing.T) {
testMessage := "@badges=;color=;display-name=pajlada;emotes=;mod=0;room-id=11148817;subscriber=0;tmi-sent-ts=1522855191000;turbo=0;user-id=11148817;user-type= :[email protected] PRIVMSG #pajlada :\u0001ACTION\u0001"

message := ParseMessage(testMessage)
msg := message.(*PrivateMessage)

assertStringsEqual(t, "11148817", msg.User.ID)
assertStringsEqual(t, "", msg.Message)
}

func TestCantParseNoTagsMessage(t *testing.T) {
testMessage := "my test message"

Expand Down

0 comments on commit 5da4523

Please sign in to comment.