-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
start_command.go
54 lines (43 loc) · 1.18 KB
/
start_command.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
package tgbot
import (
"fmt"
"github.com/nekomeowww/insights-bot/pkg/types/telegram"
"github.com/samber/lo"
)
type startCommandHandler struct {
helpCommandHandler *helpCommandHandler
startCommandHandlers []Handler
}
func newStartCommandHandler() *startCommandHandler {
h := &startCommandHandler{
startCommandHandlers: make([]Handler, 0),
}
return h
}
func (h *startCommandHandler) Command() string {
return "start"
}
func (h *startCommandHandler) CommandHelp() string {
return "开始与 Bot 的交互"
}
func (h *startCommandHandler) handle(c *Context) (Response, error) {
is, err := c.IsBotAdministrator()
if err != nil {
c.Logger.Error("failed to check if bot is administrator")
}
if is &&
c.Update.Message != nil &&
c.Update.Message.Chat != nil &&
lo.Contains([]telegram.ChatType{telegram.ChatTypeGroup, telegram.ChatTypeSuperGroup}, telegram.ChatType(c.Update.Message.Chat.Type)) &&
c.Update.Message.CommandWithAt() != fmt.Sprintf("%s@%s", h.Command(), c.Bot.Self.UserName) {
return nil, nil
}
for _, h := range h.startCommandHandlers {
_, _ = h.Handle(c)
if c.IsAborted() {
return nil, nil
}
continue
}
return h.helpCommandHandler.handle(c)
}