From f606a7575f3df9b6b6e39068ba386a8278735e3b Mon Sep 17 00:00:00 2001 From: RikaCelery Date: Sun, 13 Oct 2024 22:37:54 +0800 Subject: [PATCH] At Pattern use `message.ID` parameters --- pattern.go | 4 ++-- pattern_test.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pattern.go b/pattern.go index 421dcba..5ed1811 100644 --- a/pattern.go +++ b/pattern.go @@ -119,14 +119,14 @@ func (p *Pattern) Text(regex string) *Pattern { } // At use regex to match an 'at' segment, if id is not empty, only match specific target -func (p *Pattern) At(id ...string) *Pattern { +func (p *Pattern) At(id ...message.ID) *Pattern { if len(id) > 1 { panic("at pattern only support one id") } pattern := PatternSegment{ typ: "at", parse: func(msg *message.Segment) *PatternParsed { - if len(id) == 0 || len(id) == 1 && id[0] == msg.Data["qq"] { + if len(id) == 0 || len(id) == 1 && id[0].String() == msg.Data["qq"] { return &PatternParsed{ value: msg.Data["qq"], msg: msg, diff --git a/pattern_test.go b/pattern_test.go index 8d20958..aefd3c3 100644 --- a/pattern_test.go +++ b/pattern_test.go @@ -87,7 +87,7 @@ func TestPattern_At(t *testing.T) { {[]message.Segment{message.Text("haha")}, NewPattern().At(), false}, {[]message.Segment{message.Image("not a image")}, NewPattern().At(), false}, {[]message.Segment{message.At(114514)}, NewPattern().At(), true}, - {[]message.Segment{message.At(114514)}, NewPattern().At("1919810"), false}, + {[]message.Segment{message.At(114514)}, NewPattern().At(message.NewMessageIDFromString("1919810")), false}, } for i, v := range textTests { t.Run(strconv.Itoa(i), func(t *testing.T) { @@ -208,7 +208,7 @@ func TestAllParse(t *testing.T) { value: []string{"haha", "h", "a", "h", "a"}, }, }}, - {[]message.Segment{message.Reply("fake reply"), message.Image("fake image"), message.At(999), message.At(124), message.Text("haha")}, NewPattern().Reply().Image().At().At("124").Text("(h)(a)(h)(a)"), []PatternParsed{ + {[]message.Segment{message.Reply("fake reply"), message.Image("fake image"), message.At(999), message.At(124), message.Text("haha")}, NewPattern().Reply().Image().At().At(message.NewMessageIDFromInteger(124)).Text("(h)(a)(h)(a)"), []PatternParsed{ { value: "fake reply",