-
Notifications
You must be signed in to change notification settings - Fork 0
/
tgraph.go
50 lines (44 loc) · 1.24 KB
/
tgraph.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
44
45
46
47
48
49
50
package tgraph
import (
"github.com/andatoshiki/telegraph-go"
"github.com/andatoshiki/toshiki-rssbot/internal/config"
"github.com/andatoshiki/toshiki-rssbot/internal/log"
)
var (
authToken = config.TelegraphToken
socks5Proxy = config.Socks5
clientPool []*telegraph.Client
)
func init() {
if config.EnableTelegraph {
log.Infof("telegraph enabled, count %d, %#v", len(authToken), authToken)
for _, t := range authToken {
client, err := telegraph.Load(t, socks5Proxy)
if err != nil {
log.Errorf("telegraph load %s failed, %v", t, err)
} else {
clientPool = append(clientPool, client)
}
}
if len(clientPool) == 0 {
if config.TelegraphAccountName == "" {
config.EnableTelegraph = false
log.Error("telegraph token error, telegraph disabled")
} else if len(authToken) == 0 {
// create account
client, err := telegraph.Create(
config.TelegraphAccountName,
config.TelegraphAuthorName,
config.TelegraphAuthorURL,
config.Socks5,
)
if err != nil {
config.EnableTelegraph = false
log.Errorf("create telegraph account failed, %v", err)
}
clientPool = append(clientPool, client)
log.Infof("create telegraph account success, token %v", client.AccessToken)
}
}
}
}