forked from jqs7/Jqs7Bot
/
init.go
70 lines (61 loc) · 1.44 KB
/
init.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"log"
"github.com/Syfaro/telegram-bot-api"
"github.com/fatih/set"
"github.com/kylelemons/go-gypsy/yaml"
"gopkg.in/redis.v3"
)
var (
bot *tgbotapi.BotAPI
conf *yaml.File
rc *redis.Client
categories []string
vimtips chan Tips
hitokoto chan Hitokoto
sticker chan string
turingAPI string
categoriesSet set.Interface
msID string
msSecret string
)
func init() {
rc = redis.NewClient(&redis.Options{
Addr: "localhost:6379",
})
// Init categories
categories = []string{
"Linux", "Programming", "Software",
"影音", "科幻", "ACG", "IT", "社区",
"闲聊", "资源", "同城", "Others",
}
categoriesSet = set.New(set.NonThreadSafe)
for _, v := range categories {
categoriesSet.Add(v)
}
LoadConf()
botapi, _ := conf.Get("botapi")
vimTipsCache, _ := conf.GetInt("vimTipsCache")
hitokotoCache, _ := conf.GetInt("hitokotoCache")
vimtips = new(Tips).GetChan(int(vimTipsCache))
hitokoto = new(Hitokoto).GetChan(int(hitokotoCache))
sticker = RandSticker(rc)
var err error
bot, err = tgbotapi.NewBotAPI(botapi)
if err != nil {
log.Panic(err)
}
u := tgbotapi.NewUpdate(0)
u.Timeout = 60
bot.UpdatesChan(u)
}
func LoadConf() {
var err error
conf, err = yaml.ReadFile("botconf.yaml")
if err != nil {
log.Panic(err)
}
turingAPI, _ = conf.Get("turingBotKey")
msID, _ = conf.Get("msTransId")
msSecret, _ = conf.Get("msTransSecret")
}