Expand twitter t.co links
This commit is contained in:
parent
3dfc38b0f5
commit
dfb56be55f
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue