This repository has been archived by the owner on Mar 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
120 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package trigger | ||
|
||
import "fmt" | ||
|
||
type Email struct{ | ||
text string | ||
} | ||
|
||
func NewEmail() *Email { | ||
return &Email{} | ||
} | ||
|
||
func (t *Email) Cond(text string) bool { | ||
return true | ||
} | ||
|
||
func (t *Email) Handle() { | ||
fmt.Println("Email handle") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package trigger | ||
|
||
import ( | ||
"github.com/tsundata/assistant/internal/app/message/trigger/tags" | ||
"regexp" | ||
) | ||
|
||
type Tag struct { | ||
text string | ||
t []tags.Tagger | ||
} | ||
|
||
func NewTag() *Tag { | ||
return &Tag{} | ||
} | ||
|
||
func (t *Tag) Cond(text string) bool { | ||
re := regexp.MustCompile(`(?m)#(\w+)(\s+)?`) | ||
ts := re.FindAllString(text, -1) | ||
|
||
if len(ts) > 0 { | ||
for _, item := range ts { | ||
mt := tags.MapTagger(item) | ||
if mt != nil { | ||
t.t = append(t.t, mt) | ||
} | ||
} | ||
return true | ||
} | ||
|
||
return false | ||
} | ||
|
||
func (t *Tag) Handle() { | ||
for _, item := range t.t { | ||
item.Handle(t.text) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package tags | ||
|
||
type Issue struct {} | ||
|
||
func NewIssue() *Issue { | ||
return &Issue{} | ||
} | ||
|
||
func (t *Issue) Handle(text string) { | ||
panic("implement me") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package tags | ||
|
||
type Tagger interface { | ||
Handle(text string) | ||
} | ||
|
||
func MapTagger(text string) Tagger { | ||
m := map[string]Tagger{ | ||
"issue": NewIssue(), | ||
"todo": NewTodo(), | ||
} | ||
if t, ok := m[text]; ok { | ||
return t | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package tags | ||
|
||
type Todo struct {} | ||
|
||
func NewTodo() *Todo { | ||
return &Todo{} | ||
} | ||
|
||
func (t *Todo) Handle(text string) { | ||
panic("implement me") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package trigger | ||
|
||
import "fmt" | ||
|
||
type User struct { | ||
text string | ||
} | ||
|
||
func NewUser() *User { | ||
return &User{} | ||
} | ||
|
||
func (t *User) Cond(text string) bool { | ||
return true | ||
} | ||
|
||
func (t *User) Handle() { | ||
fmt.Println("User handle") | ||
} |