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
/
templates.go
175 lines (145 loc) · 3.49 KB
/
templates.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package main
import (
"fmt"
"net/url"
"strings"
"time"
)
const (
messageAPI = "https://api.telegram.org/bot%s/sendMessage?chat_id=%d&text=%s"
weekdayInlineButtonText = "%s (%d.%d)"
weekdayInlineButtonData = `{"date":%d,"action":%d}`
homeworkReply = "\n" +
"*%d.* _%s_" +
"\n" +
"*%s:* %s" +
"\n" +
"*%s:* %d.%d.%d" +
"\n"
alertReply = "\n" +
"*%d.* _%s_" +
"\n" +
"*%s:* %d.%d.%d %d:%d" +
"\n"
cronAlert = "*Alert*" +
"\n" +
"%s"
)
func GenerateCronAlert(alert string) string {
return fmt.Sprintf(cronAlert, alert)
}
func GenerateMessageURL(botToken string, chatID int, message string) string {
return fmt.Sprintf(messageAPI, botToken, chatID, url.QueryEscape(message))
}
func GenerateScheduleMessage(schedule map[string]interface{}) string {
var (
reply = ""
sliceSchedule = schedule["data"].([]interface{})
)
for index, scheduleTime := range sliceSchedule{
reply += scheduleTime.(string)
if (index+1)%2 == 0 {
reply += "\n"
} else {
reply += " - "
}
}
return reply
}
func GenerateTimetableMessage(subjects map[string]interface{}) string {
l.SetDomain("weekdays")
var (
reply = []string{
"*" + l.Gettext(time.Monday.String()) + "*" + "\n",
"*" + l.Gettext(time.Tuesday.String()) + "*" + "\n",
"*" + l.Gettext(time.Wednesday.String()) + "*" + "\n",
"*" + l.Gettext(time.Thursday.String()) + "*" + "\n",
"*" + l.Gettext(time.Friday.String()) + "*" + "\n",
"*" + l.Gettext(time.Saturday.String()) + "*" + "\n",
}
)
for weekday, subjectInterfaces := range subjects {
for _, subjectName := range subjectInterfaces.([]interface{}) {
switch strings.Title(weekday) {
case time.Monday.String():
reply[0] += subjectName.(string) + "\n"
case time.Tuesday.String():
reply[1] += subjectName.(string) + "\n"
case time.Wednesday.String():
reply[2] += subjectName.(string) + "\n"
case time.Thursday.String():
reply[3] += subjectName.(string) + "\n"
case time.Friday.String():
reply[4] += subjectName.(string) + "\n"
case time.Saturday.String():
reply[5] += subjectName.(string) + "\n"
}
}
}
return strings.Join(reply, "\n")
}
func GenerateAlertMessage(alerts []map[string]interface{}) string {
var reply = ""
l.SetDomain("general")
if alerts != nil {
for index, alert := range alerts {
alertDate := time.Unix(alert["date"].(int64), 0)
reply += fmt.Sprintf(
alertReply,
index+1,
alert["content"].(string),
l.Gettext("Onto"),
alertDate.Day(),
alertDate.Month(),
alertDate.Year(),
alertDate.Hour(),
alertDate.Minute(),
)
}
return reply
}
return l.Gettext("No alerts detected")
}
func GenerateHomeworkMessage(homeworks []map[string]interface{}) string {
var reply = ""
l.SetDomain("general")
if homeworks != nil {
for index, homework := range homeworks {
homeworkDeadline := time.Unix(homework["deadline"].(int64), 0)
reply += fmt.Sprintf(
homeworkReply,
index+1,
homework["subject"].(string),
l.Gettext("Task"),
homework["task"].(string),
l.Gettext("Deadline"),
homeworkDeadline.Day(),
homeworkDeadline.Month(),
homeworkDeadline.Year(),
)
}
return reply
}
return l.Gettext("No homeworks detected")
}
func WeekdayInlineButtonText(
monthName string,
date time.Time,
) string {
return fmt.Sprintf(
weekdayInlineButtonText,
monthName,
date.Day(),
date.Month(),
)
}
func WeekdayInlineButtonData(
date int64,
action int64,
) string {
return fmt.Sprintf(
weekdayInlineButtonData,
date,
action,
)
}