-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand_callback_functions.py
65 lines (58 loc) · 2.42 KB
/
command_callback_functions.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
from app import slack
import json
from blocks import get_base_context_blocks
from db_manage import join_user, unjoin_user, register_user, unregister_user, update_evaluation
from callback_message_functions import callback_command_view_message, callback_invitation_message,\
callback_evaluation_message
def get_update_message(data):
"""
:param data: payload from command callback
:return string: update message based on callback case
"""
user_action = data['actions'][0]['value']
input_blocks_type = data['actions'][0]['block_id']
if input_blocks_type == "command_view_blocks":
update_message = callback_command_view_message(user_action)
elif input_blocks_type == "invitation_blocks":
update_message = callback_invitation_message(user_action)
elif input_blocks_type.startswith("evaluation_blocks"):
update_message = callback_evaluation_message(input_blocks_type)
return update_message
def update_command_view(data, service_enable_time):
"""
update message based on whether current time is service enable time
:param data: payload from command callback
:param service_enable_time: boolean
"""
ts = data['message']['ts']
channel = data['channel']['id']
if service_enable_time:
update_message = get_update_message(data)
else:
update_message = "매칭 준비중입니다. 자정 12시 이후에 다시 시도해주세요."
blocks = get_base_context_blocks(update_message)
slack.chat.update(channel=channel, ts=ts, text="edit-text", blocks=json.dumps(blocks))
def update_user(data):
"""
:param data: payload from command callback
"""
user_slack_id = data['user']['id']
user_action = data['actions'][0]
if user_action['value'] == 'register':
register_user(user_slack_id)
elif user_action['value'] == 'unregister':
unregister_user(user_slack_id)
elif user_action['value'] == 'join':
join_user(user_slack_id)
elif user_action['value'] == 'unjoin':
unjoin_user(user_slack_id)
def update_database(data):
"""
update database based on callback case
:param data: payload from command callback
"""
input_blocks_type = data['actions'][0]['block_id']
if input_blocks_type in ["command_view_blocks", "invitation_blocks"]:
update_user(data)
elif input_blocks_type.startswith("evaluation_blocks"):
update_evaluation(data)