This repository has been archived by the owner on Oct 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.go
98 lines (90 loc) · 1.94 KB
/
start.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
88
89
90
91
92
93
94
95
96
97
98
package main
import (
"github.com/sinnrrr/schoolbot/db"
tb "gopkg.in/tucnak/telebot.v2"
"strconv"
)
func handleStartCommand() {
l.SetDomain("dialogue")
bot.Handle("/start", func(m *tb.Message) {
if m.Private() {
if m.Payload != "" {
classID, err := strconv.ParseInt(m.Payload, 10, 64)
if err != nil {
panic(err)
}
student, err := db.CreateStudent(m.Sender, classID)
if err != nil {
panic(err)
}
if student == nil {
handleSendError(
bot.Send(
m.Sender,
l.Gettext("You have already accepted the invite from this group :p"),
keyboard,
),
)
} else {
handleSendError(
bot.Send(
m.Chat,
l.Gettext("Hello, how can I help my good old friend? :)"),
keyboard,
),
)
}
} else {
handleSendError(
bot.Send(
m.Chat,
l.Gettext("To get things started, please add me to your class group :]"),
&tb.ReplyMarkup{
InlineKeyboard: groupInviteKeys,
},
),
)
}
} else {
handleSendError(
bot.Send(
m.Chat,
l.Gettext("Hello, how can I help in your group?"),
keyboard,
),
)
}
})
}
func handleOnAddedEvent() {
bot.Handle(tb.OnAddedToGroup, func(m *tb.Message) {
class, err := db.CreateClass(m.Chat.ID, m.Chat.Title)
if err != nil {
panic(err)
}
if class == nil {
handleSendError(
bot.Send(
m.Chat,
l.Gettext("Your group have already records in our database"),
),
)
} else {
handleSendError(
bot.Send(
m.Chat,
l.Gettext("Hey guys! Click this button in order to have access to create and read homeworks and alerts from ths group ;p"),
&tb.ReplyMarkup{
InlineKeyboard: generatePersonalInviteKeys(m.Chat.ID),
},
),
)
}
})
}
func handleSendError(m *tb.Message, err error) {
if err != nil {
bot.Send(m.Chat, l.Gettext("Something went wrong with bot. Please, try again later."))
panic(err)
}
}