-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
89 lines (83 loc) · 2.25 KB
/
main.go
File metadata and controls
89 lines (83 loc) · 2.25 KB
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
88
89
// MirrorBotGo project main.go
package main
import (
"MirrorBotGo/engine"
"MirrorBotGo/modules/authorization"
"MirrorBotGo/modules/botlog"
"MirrorBotGo/modules/cancelmirror"
"MirrorBotGo/modules/clone"
"MirrorBotGo/modules/configuration"
"MirrorBotGo/modules/list"
"MirrorBotGo/modules/mirror"
"MirrorBotGo/modules/mirrorstatus"
"MirrorBotGo/modules/ping"
"MirrorBotGo/modules/shell"
"MirrorBotGo/modules/start"
"MirrorBotGo/modules/stats"
"MirrorBotGo/utils"
"net/http"
"os"
"os/signal"
"time"
_ "net/http/pprof"
"github.com/PaulSonOfLars/gotgbot/v2"
"github.com/PaulSonOfLars/gotgbot/v2/ext"
"go.uber.org/zap"
)
func ExitCleanup() {
killSignal := make(chan os.Signal, 1)
signal.Notify(killSignal, os.Interrupt)
<-killSignal
engine.CancelAllMirrors()
engine.L().Info("Exit Cleanup")
err := utils.RemoveByPath(utils.GetDownloadDir())
if err != nil {
engine.L().Errorf("Error while removing dir: %s : %v\n", utils.GetDownloadDir(), err)
}
os.Exit(1)
}
func RegisterAllHandlers(updater *ext.Updater, l *zap.SugaredLogger) {
start.LoadStartHandler(updater, l)
mirror.LoadMirrorHandlers(updater, l)
mirrorstatus.LoadMirrorStatusHandler(updater, l)
cancelmirror.LoadCancelMirrorHandler(updater, l)
list.LoadListHandler(updater, l)
authorization.LoadAuthorizationHandlers(updater, l)
stats.LoadStatsHandler(updater, l)
ping.LoadPingHandler(updater, l)
clone.LoadCloneHandler(updater, l)
botlog.LoadLogHandler(updater, l)
shell.LoadShellHandlers(updater, l)
configuration.LoadConfigurationHandlers(updater, l)
}
func main() {
router := engine.NewHealthRouter()
router.StartWebServer(utils.GetHealthCheckRouterURL())
l := engine.GetLogger()
token := utils.GetBotToken()
l.Info("Starting Bot.")
b, err := gotgbot.NewBot(token, &gotgbot.BotOpts{
Client: http.Client{},
DefaultRequestOpts: &gotgbot.RequestOpts{
Timeout: 20 * time.Second,
},
})
if err != nil {
l.Fatal(err)
}
updater := ext.NewUpdater(&ext.UpdaterOpts{
DispatcherOpts: ext.DispatcherOpts{
MaxRoutines: -1,
},
})
l.Info("Starting updater")
RegisterAllHandlers(&updater, l)
go ExitCleanup()
err = updater.StartPolling(b, nil)
if err != nil {
l.Fatalf("Error occurred at start of polling : %s", err.Error())
return
}
l.Info("Started Updater.")
updater.Idle()
}