forked from humblEgo/42mate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblocks.py
272 lines (258 loc) · 8.23 KB
/
blocks.py
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
def get_base_blocks(text):
"""
convert text to slack section blocks format
:param text: string
:return list: slack blocks contained text
"""
base_blocks = [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": text
}
}
]
return base_blocks
def get_base_context_blocks(text):
"""
convert text to slack context blocks format
:param text: string
:return list: slack blocks contained text
"""
blocks = [
{
"type": "context",
"elements": [
{"type": "mrkdwn", "text": text}
]
}
]
return blocks
def get_action_blocks_by(user_info):
"""
:param user_info: dictionary
:return list: slack blocks contained possible action buttons
"""
register_action = {
"type": "button",
"text": {
"type": "plain_text",
"text": "42mate 등록하기"
},
"style": "primary",
"value": "register"
}
join_action = {
"type": "button",
"text": {
"type": "plain_text",
"text": "내일 만나기"
},
"style": "primary",
"value": "join"
}
unjoin_action = {
"type": "button",
"text": {
"type": "plain_text",
"text": "내일 만나지 않기"
},
"style": "danger",
"value": "unjoin"
}
unregister_action = {
"type": "button",
"text": {
"type": "plain_text",
"text": "42mate 휴식하기"
},
"style": "danger",
"value": "unregister",
"confirm": {
"title": {
"type": "plain_text",
"text": "정말 휴식하시겠어요?"
},
"text": {
"type": "mrkdwn",
"text": "앞으로 메이트 매칭에 참여할 수 없습니다."
},
"confirm": {
"type": "plain_text",
"text": "휴식하기"
},
"deny": {
"type": "plain_text",
"text": "더 생각해보기"
}
}
}
action_blocks = {
"type": "actions",
"block_id": "command_view_blocks",
"elements": []
}
user_state = user_info['state']
if user_state == "registered":
action_blocks['elements'] = [join_action, unregister_action]
elif user_state == "joined":
action_blocks['elements'] = [unjoin_action, unregister_action]
elif user_state == "unjoined":
action_blocks['elements'] = [join_action, unregister_action]
elif user_state == "unregistered":
action_blocks['elements'] = [register_action]
return action_blocks
def get_command_view_blocks(user_info):
"""
:param user_info: dictionary
:return list: slack blocks that combines base blocks and action blocks
"""
blocks = get_base_blocks(user_info['intra_id'] + "님, 안녕하세요! 무엇을 도와드릴까요?")
action_blocks = get_action_blocks_by(user_info)
blocks.append(action_blocks)
return blocks
def get_evaluation_blocks(evaluation):
"""
make evaluation blocks with user name and mate name in evaluation
:param evaluation: Evaluation
:return list: slack blocks that contains evaluation blocks
"""
evaluation_blocks = [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text":"*" + evaluation.user.intra_id + "* 님, 어제 메이트 *" + evaluation.mate.intra_id + "* 님과의 시간은 얼마나 만족스러우셨나요? :ghost:"
}
},
{
"type": "actions",
"block_id": "evaluation_blocks_" + str(evaluation.index),
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": ":star:",
"emoji": True
},
"value": "10"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": ":star::star:",
"emoji": True
},
"value": "20"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": ":star::star::star:",
"emoji": True
},
"value": "30"
},
{
"action_id": "evaluation",
"type": "button",
"text": {
"type": "plain_text",
"text": ":star::star::star::star:",
"emoji": True
},
"value": "40"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": ":star::star::star::star::star:",
"emoji": True
},
"value": "50"
}
]
}
]
return evaluation_blocks
def get_match_blocks(match):
"""
make match blocks with matched users' name and activity
:param match: Match
:return list: slack blocks that contains match guide message
"""
text = "따-단! *" + match.users[0].intra_id + "* 님과 *" + match.users[1].intra_id + "* 님은 오늘의 메이트입니다. \n" \
+ "온라인 미션과 함께 서로에 대해 알아가며 흥미로운 시간을 만들어보세요. \n" \
+ "곧 클러스터에서 만나면 반갑게 인사할 수 있게요!"
blocks = get_base_blocks(text)
blocks.append({"type": "divider"})
content = {
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*우리를 가깝게 만들 온라인 미션 : " + match.activity.subject + "* :sunglasses:\n" + match.activity.content
}
}
blocks.append(content)
blocks.append({"type": "divider"})
return blocks
def get_info_blocks(user_info):
"""
:param user_info: dictionary
:return list: slack blocks that contains information based on user state
"""
if user_info['current_mate']:
text = "오늘의 메이트는 *" + user_info['current_mate'] + "* 님입니다. "
else:
text = "오늘은 메이트가 없습니다."
if user_info['state'] == 'joined':
text += "내일 참여가 예약되어 있습니다."
elif user_info['state'] == 'unjoined':
text += "내일 참여가 예약되어 있지 않습니다."
elif user_info['state'] == 'unregistered':
text += "앞으로 메이트 매칭이 진행되지 않습니다."
blocks = [{"type": "context", "elements": [{"type": "mrkdwn", "text": text}]}]
return blocks
def get_invitation_blocks():
"""
:return list: slack blocks that contains invitation blocks
"""
invitation_blocks = [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "안녕하세요. 내일, 당신의 메이트와 만나보시겠어요? :smile:"
}
},
{
"type": "actions",
"block_id": "invitation_blocks",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "응! 만나고 싶어."
},
"style": "primary",
"value": "join"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": "아니, 내일은 스킵-"
},
"style": "danger",
"value": "unjoin"
}
]
}
]
return invitation_blocks