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
/
keyboard.go
126 lines (108 loc) · 2.35 KB
/
keyboard.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package main
import (
"github.com/sinnrrr/schoolbot/db"
tb "gopkg.in/tucnak/telebot.v2"
)
var (
keyboard = &tb.ReplyMarkup{ResizeReplyKeyboard: true, OneTimeKeyboard: true}
)
func registerKeyboard() {
l.SetDomain("general")
var (
newButton = keyboard.Text(l.Gettext("New"))
homeworkButton = keyboard.Text(l.Gettext("Homeworks"))
timetableButton = keyboard.Text(l.Gettext("Timetable"))
alertButton = keyboard.Text(l.Gettext("Alerts"))
settingsButton = keyboard.Text(l.Gettext("Settings"))
)
keyboard.Reply(
keyboard.Row(newButton),
keyboard.Row(homeworkButton, timetableButton),
keyboard.Row(alertButton, settingsButton),
)
l.SetDomain("dialogue")
bot.Handle(&newButton, newButtonHandler)
bot.Handle(&homeworkButton, homeworkButtonHandler)
bot.Handle(&timetableButton, timetableButtonHandler)
bot.Handle(&alertButton, alertButtonHandler)
bot.Handle(&settingsButton, settingsButtonHandler)
}
func newButtonHandler(m *tb.Message) {
l.SetDomain("dialogue")
handleSendError(
bot.Send(
m.Chat,
l.Gettext("What do you want to create today, master?"),
operationInlineKeyboard,
),
)
}
func homeworkButtonHandler(m *tb.Message) {
homeworks, err := db.QueryHomework(m.Sender.ID)
if err != nil {
panic(err)
}
handleSendError(
bot.Send(
m.Chat,
GenerateHomeworkMessage(homeworks),
keyboard,
tb.ModeMarkdown,
),
)
}
func alertButtonHandler(m *tb.Message) {
alerts, err := db.QueryAlert(m.Sender.ID)
if err != nil {
panic(err)
}
handleSendError(
bot.Send(
m.Chat,
GenerateAlertMessage(alerts),
keyboard,
tb.ModeMarkdown,
),
)
}
func timetableButtonHandler(m *tb.Message) {
l.SetDomain("dialogue")
timetable, err := db.StudentTimetable(m.Sender.ID)
if err != nil {
panic(err)
}
if timetable == nil {
handleSendError(
bot.Send(
m.Chat,
l.Gettext("Timetable for your class hasn't been created yet"),
createTimetableInlineKeyboard,
),
)
} else {
handleSendError(
bot.Send(
m.Chat,
GenerateTimetableMessage(timetable[0]),
tb.ModeMarkdown,
),
)
handleSendError(
bot.Send(
m.Chat,
GenerateScheduleMessage(timetable[1]),
keyboard,
),
)
}
}
func settingsButtonHandler(m *tb.Message) {
l.SetDomain("general")
handleSendError(
bot.Send(
m.Chat,
l.Gettext("Go ahead, tweak me"),
settingsInlineKeyboard,
),
)
}