-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
50 lines (46 loc) · 1.25 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
package main
import (
"context"
_ "embed"
"github.com/go-telegram/bot"
)
//go:embed manifest.plist
var plistTemplate string
//go:embed install.html
var installPageTemplate string
var handlerGroup *HandlerGroup
var config *Config
func main() {
config = NewConfig()
SetupClient()
SetupS3()
tgBot, err := bot.New(config.Token, bot.WithDebug(),
bot.WithDefaultHandler(WrapHandlerGroupFunc(defaultHandler)),
bot.WithServerURL(config.Server))
if err != nil {
panic(err)
}
handlerGroup = NewHandlerGroup()
tgBot.RegisterHandler(bot.HandlerTypeMessageText, "/start", bot.MatchTypePrefix,
WrapHandlerGroupFunc(handlerGroup.Start))
tgBot.RegisterHandler(bot.HandlerTypeMessageText, "/list", bot.MatchTypePrefix,
WrapHandlerGroupFunc(handlerGroup.List))
tgBot.RegisterHandler(bot.HandlerTypeCallbackQueryData, "list_", bot.MatchTypePrefix,
WrapHandlerGroupFunc(handlerGroup.ListSwitchPage))
ctx := context.Background()
tgBot.Start(ctx)
}
func defaultHandler(update *Update) {
if update.Message == nil {
return
}
session := NewSession(update.Message.Chat.ID)
if session.State != SessionStateDefault {
return
}
if update.Message.Document == nil {
update.MustSendReplyMessage("Please upload a .ipa file")
return
}
handlerGroup.UploadIPA(update)
}