Skip to content

Commit 05eb657

Browse files
taki73claude
andcommitted
fix: ++/--/== の後に文字列が続く場合は反応しないよう修正
オペレーターの後に別の単語が続く場合(例: `:neko: -- Settings`)は 意図的な操作ではなく文章の一部である可能性が高いため、 ++/--/== の直後がスペースのみ・行末・改行の場合のみ反応するよう正規表現を修正した。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 91c7dae commit 05eb657

2 files changed

Lines changed: 66 additions & 2 deletions

File tree

bot/bot.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ const (
8484
// Pre-compiled regexes for detecting point operations with targets
8585
var (
8686
// User mention pattern: <@U123456> ++ (captures user ID and operator)
87-
userOperationPattern = regexp.MustCompile(`<@([A-Z0-9]+)>[  ]*(\+\+|-{2}|={2})`)
87+
userOperationPattern = regexp.MustCompile(`<@([A-Z0-9]+)>[  ]*(\+\+|-{2}|={2})[  ]*($|\n)`)
8888
// Emoji pattern: :emoji: ++ (captures emoji name and operator)
89-
emojiOperationPattern = regexp.MustCompile(`:([a-zA-Z0-9_+-]+):[  ]*(\+\+|-{2}|={2})`)
89+
emojiOperationPattern = regexp.MustCompile(`:([a-zA-Z0-9_+-]+):[  ]*(\+\+|-{2}|={2})[  ]*($|\n)`)
9090
)
9191

9292
// parseOperator converts an operator string to a PointOperation

bot/bot_test.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,70 @@ func TestDetectOperationAndTarget(t *testing.T) {
383383
wantTarget: "U123456",
384384
wantIsUser: true,
385385
},
386+
// Operator must be at end of line or followed by newline
387+
{
388+
name: "Emoji operator followed by text",
389+
text: ":nya-nya: -- Settings",
390+
wantOp: NoOperation,
391+
wantTarget: "",
392+
wantIsUser: false,
393+
},
394+
{
395+
name: "Emoji operator followed by text (plus)",
396+
text: ":neko: ++ foo",
397+
wantOp: NoOperation,
398+
wantTarget: "",
399+
wantIsUser: false,
400+
},
401+
{
402+
name: "Emoji operator followed by text (equals)",
403+
text: ":neko: == foo",
404+
wantOp: NoOperation,
405+
wantTarget: "",
406+
wantIsUser: false,
407+
},
408+
{
409+
name: "Emoji operator followed by trailing spaces",
410+
text: ":neko: ++ ",
411+
wantOp: PointUp,
412+
wantTarget: "neko",
413+
wantIsUser: false,
414+
},
415+
{
416+
name: "Emoji operator followed by newline",
417+
text: ":neko: ++\n",
418+
wantOp: PointUp,
419+
wantTarget: "neko",
420+
wantIsUser: false,
421+
},
422+
{
423+
name: "Emoji operator followed by newline and text",
424+
text: ":neko: ++\nsome text",
425+
wantOp: PointUp,
426+
wantTarget: "neko",
427+
wantIsUser: false,
428+
},
429+
{
430+
name: "User operator followed by text",
431+
text: "<@U123456> ++ foo",
432+
wantOp: NoOperation,
433+
wantTarget: "",
434+
wantIsUser: false,
435+
},
436+
{
437+
name: "User operator followed by trailing spaces",
438+
text: "<@U123456> ++ ",
439+
wantOp: PointUp,
440+
wantTarget: "U123456",
441+
wantIsUser: true,
442+
},
443+
{
444+
name: "User operator followed by newline and text",
445+
text: "<@U123456> ++\nsome text",
446+
wantOp: PointUp,
447+
wantTarget: "U123456",
448+
wantIsUser: true,
449+
},
386450
}
387451

388452
for _, tt := range tests {

0 commit comments

Comments
 (0)