Skip to content

Commit

Permalink
Implement global CLEARCHAT message parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
pajlada committed May 26, 2018
1 parent 6ff9e1e commit 38f6b31
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ func parseOtherMessage(line string) *message {
msg.Type = ROOMSTATE
case "USERNOTICE":
msg.Type = USERNOTICE
case "CLEARCHAT":
msg.Type = CLEARCHAT
}
msg.Tags = make(map[string]string)

Expand All @@ -111,6 +113,10 @@ func parseOtherMessage(line string) *message {

msg.Tags[tagSplit[0]] = value
}

if msg.Type == CLEARCHAT {
msg.Text = "Chat has been cleared by a moderator"
}
return msg
}

Expand Down
14 changes: 14 additions & 0 deletions message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@ func TestCanParseClearChatMessage(t *testing.T) {
if message.Type != CLEARCHAT {
t.Error("parsing CLEARCHAT message failed")
}

assertStringsEqual(t, message.Channel, "pajlada")
}

func TestCanParseClearChatMessage2(t *testing.T) {
testMessage := `@room-id=11148817;tmi-sent-ts=1527342985836 :tmi.twitch.tv CLEARCHAT #pajlada`

message := parseMessage(testMessage)

if message.Type != CLEARCHAT {
t.Error("parsing CLEARCHAT message failed")
}

assertStringsEqual(t, message.Channel, "pajlada")
}

func TestCanParseEmoteMessage(t *testing.T) {
Expand Down

0 comments on commit 38f6b31

Please sign in to comment.