Skip to content

Commit

Permalink
Fix twitter regexp to handle x.com as well
Browse files Browse the repository at this point in the history
  • Loading branch information
ailinykh committed Aug 14, 2023
1 parent 59475a8 commit b6a703f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion usecases/twitter_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type TwitterParser struct {

// HandleText is a core.ITextHandler protocol implementation
func (parser *TwitterParser) HandleText(message *core.Message, bot core.IBot) error {
r := regexp.MustCompile(`https://twitter\.com\S+/(\d+)\S*`)
r := regexp.MustCompile(`https://(?i:twitter|x)\.com\S+/(\d+)\S*`)
match := r.FindAllStringSubmatch(message.Text, -1)

if len(match) > 0 {
Expand Down
9 changes: 9 additions & 0 deletions usecases/twitter_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ func Test_HandleText_FoundTweetLink(t *testing.T) {
assert.Equal(t, []string{"123456"}, handler.tweets)
}

func Test_HandleText_FoundTweetLinkX(t *testing.T) {
parser, handler, bot := makeTwitterSUT()
m := makeTweetMessage("a message with https://x.com/status/username/123456")

parser.HandleText(m, bot)

assert.Equal(t, []string{"123456"}, handler.tweets)
}

func Test_HandleText_FoundMultipleTweetLinks(t *testing.T) {
parser, handler, bot := makeTwitterSUT()
m := makeTweetMessage("a message with https://twitter.com/username/status/123456 and https://twitter.com/username/status/789010 and some text")
Expand Down

0 comments on commit b6a703f

Please sign in to comment.