-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
87 lines (76 loc) · 1.91 KB
/
main.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
import (
"flag"
"fmt"
uuid "github.com/satori/go.uuid"
"log"
"time"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
)
var configPath = flag.String("config", "", "Path to config file")
func main() {
flag.Parse()
config, err := GetConfig(*configPath)
if err != nil {
log.Panic(err)
return
}
httpClient, err := ProxyHttpClient(config.ProxyAddr, config.ProxyUser, config.ProxyPassword)
if err != nil {
log.Panic(err)
return
}
bot, err := tgbotapi.NewBotAPIWithClient(config.Token, httpClient)
if err != nil {
log.Panic(err)
return
}
cloudJenkinsClient, err := GetNewJenkinsClinet(JenkinsParams{
JenkinsUrl: config.CloudJenkinsUrl,
Password: config.CloudJenkinsPassword,
Username: config.CloudJenkinsUser,
})
if err != nil {
log.Panic(err)
return
}
chmodJenkinsClient, err := GetNewJenkinsClinet(JenkinsParams{
JenkinsUrl: config.ChmodJenkinsUrl,
Password: config.ChmodJenkinsPassword,
Username: config.ChmodJenkinsUser,
})
if err != nil {
log.Panic(err)
return
}
bot.Debug = true
log.Printf("Authorized on account %s", bot.Self.UserName)
u := tgbotapi.NewUpdate(0)
u.Timeout = 60
updates, err := bot.GetUpdatesChan(u)
if err != nil {
log.Panic(err)
return
}
// Do not handle a large backlog of old messages
time.Sleep(time.Millisecond * 500)
updates.Clear()
for update := range updates {
if update.Message == nil {
continue
}
guid := uuid.NewV4()
repoDir := fmt.Sprintf(config.GitRepoCloneDir + guid.String())
handler := NewMessageHandler(
HandlerParams{
bot: bot,
cloudJenkinsClient: cloudJenkinsClient,
chModJenkinsClient: chmodJenkinsClient,
git: GetNewGitClient(config.GitRepoUrl, repoDir, config.GitUser, config.GitEmail, config.GitPassword),
archiveEditor: GetNewArchiveEditor(repoDir),
users: config.TgUsers,
},
)
go handler.Handle(update)
}
}