-
Notifications
You must be signed in to change notification settings - Fork 0
/
stream.go
43 lines (35 loc) · 813 Bytes
/
stream.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"net/url"
"github.com/ChimeraCoder/anaconda"
"github.com/arjanvaneersel/twitterbot/log"
)
var StreamActive = false
func StartTwitterStream(cfg *Config, api *anaconda.TwitterApi, log *log.Logger) {
if cfg.HasSubscriptions() {
stream := api.PublicStreamFilter(url.Values{
"track": cfg.Subscriptions,
})
StreamActive = true
defer func() {
stream.Stop()
StreamActive = false
}()
for v := range stream.C {
t, ok := v.(anaconda.Tweet)
if !ok {
log.Warningf("Received a value of %T instead of anaconda.Tweet", v)
continue
}
if t.RetweetedStatus != nil {
continue
}
_, err := api.Retweet(t.Id, false)
if err != nil {
log.Errorf("Could not retweet %d: %v", t.Id, err)
continue
}
log.Infof("Retweeted %d", t.Id)
}
}
}