Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
64 changes: 64 additions & 0 deletions bot/bot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading