diff --git a/bot/bot.go b/bot/bot.go index 6046130..43a2685 100644 --- a/bot/bot.go +++ b/bot/bot.go @@ -84,9 +84,9 @@ const ( // Pre-compiled regexes for detecting point operations with targets var ( // User mention pattern: <@U123456> ++ (captures user ID and operator) - userOperationPattern = regexp.MustCompile(`<@([A-Z0-9]+)>[  ]*(\+\+|-{2}|={2})`) + userOperationPattern = regexp.MustCompile(`<@([A-Z0-9]+)>[  ]*(\+\+|-{2}|={2})[  ]*($|\n)`) // Emoji pattern: :emoji: ++ (captures emoji name and operator) - emojiOperationPattern = regexp.MustCompile(`:([a-zA-Z0-9_+-]+):[  ]*(\+\+|-{2}|={2})`) + emojiOperationPattern = regexp.MustCompile(`:([a-zA-Z0-9_+-]+):[  ]*(\+\+|-{2}|={2})[  ]*($|\n)`) ) // parseOperator converts an operator string to a PointOperation diff --git a/bot/bot_test.go b/bot/bot_test.go index 5e87772..e422621 100644 --- a/bot/bot_test.go +++ b/bot/bot_test.go @@ -383,6 +383,70 @@ func TestDetectOperationAndTarget(t *testing.T) { wantTarget: "U123456", wantIsUser: true, }, + // Operator must be at end of line or followed by newline + { + name: "Emoji operator followed by text", + text: ":nya-nya: -- Settings", + wantOp: NoOperation, + wantTarget: "", + wantIsUser: false, + }, + { + name: "Emoji operator followed by text (plus)", + text: ":neko: ++ foo", + wantOp: NoOperation, + wantTarget: "", + wantIsUser: false, + }, + { + name: "Emoji operator followed by text (equals)", + text: ":neko: == foo", + wantOp: NoOperation, + wantTarget: "", + wantIsUser: false, + }, + { + name: "Emoji operator followed by trailing spaces", + text: ":neko: ++ ", + wantOp: PointUp, + wantTarget: "neko", + wantIsUser: false, + }, + { + name: "Emoji operator followed by newline", + text: ":neko: ++\n", + wantOp: PointUp, + wantTarget: "neko", + wantIsUser: false, + }, + { + name: "Emoji operator followed by newline and text", + text: ":neko: ++\nsome text", + wantOp: PointUp, + wantTarget: "neko", + wantIsUser: false, + }, + { + name: "User operator followed by text", + text: "<@U123456> ++ foo", + wantOp: NoOperation, + wantTarget: "", + wantIsUser: false, + }, + { + name: "User operator followed by trailing spaces", + text: "<@U123456> ++ ", + wantOp: PointUp, + wantTarget: "U123456", + wantIsUser: true, + }, + { + name: "User operator followed by newline and text", + text: "<@U123456> ++\nsome text", + wantOp: PointUp, + wantTarget: "U123456", + wantIsUser: true, + }, } for _, tt := range tests {