Skip to content

Commit

Permalink
Fixed bot online message being repeated
Browse files Browse the repository at this point in the history
  • Loading branch information
Mattie112 committed Nov 12, 2024
1 parent 6824784 commit 7015130
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func parseAndFormatMessage(message string) string {
// Extracted to keep this function small
return parseModLogEntries(message)
case "CHAT":
var re = regexp.MustCompile(`(?m)] (.*): (.*)`)
var re = regexp.MustCompile(`(?mU)] (.*): (.*?)`)
match := re.FindStringSubmatch(message)

// Ignore GPS (= map pings)
Expand All @@ -142,7 +142,7 @@ func parseAndFormatMessage(message string) string {
}

// When using achievement mode, ignore all messages from the server to prevent a message-loop
if config.achievementMode && strings.HasPrefix(match[1], "<server>: ") {
if config.achievementMode && strings.HasPrefix(match[1], "<server>") {
return ""
}

Expand Down
1 change: 1 addition & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func Test_parseAndFormatMessage(t *testing.T) {
{"GPS-hide", args{message: "2022-04-14 19:41:54 [CHAT] Mattie: [gps=98,69]"}, ""},
{"GPS-show", args{message: "2022-04-14 19:41:54 [CHAT] Mattie: [gps=98,69]", config: botConfig{sendGPSPing: true}}, ":map: | `Mattie`: [gps=98,69]"},
{"message-loop-issue-#28", args{message: "2024-10-31 20:15:53 [CHAT] <server>: [color=#7289DA][Discord][Mattie]: test123[/color]", config: botConfig{achievementMode: true}}, ""},
{"message-loop-issue-#37", args{message: "2024-10-31 20:15:53 [CHAT] <server>: [color=#7289DA][Discord]FactoriGO Chat Bot is online![/color]", config: botConfig{achievementMode: true}}, ""},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 7015130

Please sign in to comment.