Skip to content

Commit

Permalink
At Pattern use message.ID parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
RikaCelery committed Oct 13, 2024
1 parent 455afde commit f606a75
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pattern.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions pattern_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit f606a75

Please sign in to comment.