-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeneral.py
52 lines (42 loc) · 1.47 KB
/
general.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
# general.py
RESPONSE_MSG = "Thanks!"
DUPL_RESPONSE_MSG = "You already responded!"
class Slash():
def __init__(self, cmd):
self.command = cmd
self.RESPONSE_MSG = "Thanks!{}{}"
self.DUPL_RESPONSE_MSG = "You already responded!"
def construct(self, id, options):
actions = []
for x, opt in enumerate(options):
actions.append({"name": opt, "text": opt, "type": "button", "value": x})
return self.constructJSONattachments(id, actions)
def constructJSONattachments(self, id, actions):
admin_json = self.getAdminJSON(id)
channel_json = self.getChannelJSON(id, actions)
return channel_json, admin_json
def getAdminJSON(self, id):
return [
{
"fallback": "Upgrade your Slack client!",
"callback_id": self.getAdminCallback(id),
"color": "#3AA3E3",
"attachment_type": "default",
"actions": [{"name": "Get Results", "text": "Get Results + Close Poll", "type": "button", "value": 0},
{"name": "Number of Responses", "text": "Number of Responses", "type": "button", "value": 1}]
}
]
def getChannelJSON(self, id, actions):
return [
{
"fallback": "Upgrade your Slack client!",
"callback_id": self.getCallback(id),
"color": "#3AA3E3",
"attachment_type": "default",
"actions": actions
}
]
def getCallback(self, id):
return self.command + '-' + str(id)
def getAdminCallback(self, id):
return self.command + '-admin-' + str(id)