Expand twitter t.co links

This commit is contained in:
Zachary Seguin 2017-05-30 22:03:54 -04:00
parent 3dfc38b0f5
commit dfb56be55f
1 changed files with 18 additions and 1 deletions

View File

@ -62,7 +62,24 @@ func init() {
demux := twitter.NewSwitchDemux()
demux.Tweet = func(tweet *twitter.Tweet) {
if userInList(users, tweet.User) {
background.Messages <- fmt.Sprintf("%s: %s", tweet.User.Name, strings.Replace(tweet.Text, "\n", " ", -1))
tweetText := strings.Replace(tweet.Text, "\n", " ", -1)
// Replace t.co URLs
for _, entity := range tweet.Entities.Urls {
tweetText = strings.Replace(tweetText, entity.URL, entity.ExpandedURL, 1)
}
// Replace t.co media URLs
for _, entity := range tweet.Entities.Media {
url := entity.MediaURLHttps
if (url == "") {
url = entity.MediaURL
}
tweetText = strings.Replace(tweetText, entity.URL, url, 1)
}
background.Messages <- fmt.Sprintf("%s: %s [@%s]", tweet.User.Name, tweetText, tweet.User.ScreenName)
}
}
demux.StreamDisconnect = func(disconnect *twitter.StreamDisconnect) {