Skip to content

Commit 4e6e64e

Browse files
committed
Merge branch 'main' of https://github.com/nehakale8/slackpoint into ritwik
2 parents 5452414 + 1e4e84e commit 4e6e64e

File tree

103 files changed

+23992
-24
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+23992
-24
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ instance/
7070

7171
# Sphinx documentation
7272
docs/_build/
73+
# Allow Sphinx documentation build
74+
!docs/build/
7375

7476
# PyBuilder
7577
.pybuilder/

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.7145407.svg)](https://doi.org/10.5281/zenodo.7145407)
55
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
66
[![Github](https://img.shields.io/badge/language-python-red.svg)](https://docs.python.org/3/)
7-
[![build](https://github.com/mithildani/se22-hw1-grp14/actions/workflows/test.yml/badge.svg)](https://github.com/mithildani/se22-hw1-grp14/actions)
7+
[![build](https://github.com/mithildani/se22-hw1-grp14/actions/workflows/test.yml/badge.svg)](https://github.com/nehakale8/slackpoint/actions)
88
[![GitHub top language](https://img.shields.io/github/languages/top/mithildani/se22-hw1-grp14)](https://docs.python.org/3/)
9-
[![GitHub last commit](https://img.shields.io/github/last-commit/mithildani/se22-hw1-grp14)](https://github.com/mithildani/se22-hw1-grp14/commits/main)
9+
[![GitHub last commit](https://img.shields.io/github/last-commit/mithildani/se22-hw1-grp14)](https://github.com/nehakale8/slackpoint/commits/main)
1010
[![codecov](https://codecov.io/gh/nehakale8/slackpoint/branch/main/graph/badge.svg?token=1H92SAVB5S)](https://codecov.io/gh/nehakale8/slackpoint)
1111

1212

app.py

+86-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@
2828

2929
@app.route("/slack/interactive-endpoint", methods=["POST"])
3030
def interactive_endpoint():
31+
"""
32+
All interactive events like button click, input fields are received in this endpoint. We use this endpoint to handle the click event of 'Add task' button of create-task command.
33+
34+
:param:
35+
:type:
36+
:raise:
37+
:return: Response object with 200 HTTP status
38+
:rtype: Response
39+
40+
"""
3141
payload = json.loads(request.form.get("payload"))
3242
if payload["type"] == "block_actions":
3343
actions = payload["actions"]
@@ -69,11 +79,31 @@ def interactive_endpoint():
6979

7080
@app.route("/")
7181
def basic():
82+
"""
83+
Health check endpoint
84+
85+
:param:
86+
:type:
87+
:raise:
88+
:return: 'Hello World' - the official health check response text
89+
:rtype: str
90+
91+
"""
7292
return "Hello World"
7393

7494

7595
@app.route("/viewpending", methods=["POST"])
7696
def vpending():
97+
"""
98+
Endpoint to view the pending tasks
99+
100+
:param:
101+
:type:
102+
:raise:
103+
:return: Response object with payload object containing details of pending tasks
104+
:rtype: Response
105+
106+
"""
77107
data = request.form
78108
channel_id = data.get("channel_id")
79109
user_id = data.get("user_id")
@@ -87,6 +117,17 @@ def vpending():
87117

88118
@app.route("/viewcompleted", methods=["POST"])
89119
def vcompleted():
120+
"""
121+
Endpoint to view the completed tasks
122+
123+
:param:
124+
:type:
125+
:raise:
126+
:return: Response object with payload object containing details of completed tasks
127+
:rtype: Response
128+
129+
"""
130+
90131
data = request.form
91132
channel_id = data.get("channel_id")
92133
user_id = data.get("user_id")
@@ -100,6 +141,17 @@ def vcompleted():
100141

101142
@app.route("/taskdone", methods=["POST"])
102143
def taskdone():
144+
"""
145+
Endpoint to mark a task as completed
146+
147+
:param:
148+
:type:
149+
:raise:
150+
:return: Response object with payload containing task completion message
151+
:rtype: Response
152+
153+
"""
154+
103155
data = request.form
104156
td = TaskDone(data)
105157
payload = td.update_points()
@@ -108,25 +160,58 @@ def taskdone():
108160

109161
@app.route("/create", methods=["POST"])
110162
def create():
163+
"""
164+
Endpoint to create a new task, this endpoint triggers an ephemeral message for the user to enter task details for creation
165+
166+
:param:
167+
:type:
168+
:raise:
169+
:return: Response object with 200 HTTP status
170+
:rtype: Response
171+
172+
"""
173+
111174
ct = CreateTask()
112175
blocks = ct.create_task_input_blocks()
176+
113177
data = request.form
114178
channel_id = data.get("channel_id")
115179
user_id = data.get("user_id")
116180
slack_client.chat_postEphemeral(channel=channel_id, user=user_id, blocks=blocks)
117-
118181
return Response(), 200
119182

120183

121184
@app.route("/help", methods=["POST"])
122185
def help():
186+
"""
187+
A helper endpoint to view all commands and how to use them
188+
189+
:param:
190+
:type:
191+
:raise:
192+
:return: Response object with payload object containing details of all commands and how to use them
193+
:rtype: Response
194+
195+
"""
196+
123197
h = Help()
124198
payload = h.help_all()
125199
return jsonify(payload)
126200

127201

128202
@app.route("/leaderboard", methods=["POST"])
129203
def leaderboard():
204+
"""
205+
Endpoint to view the leaderboard
206+
207+
:param:
208+
:type:
209+
:raise:
210+
:return: Response object with payload object containing details of champions leading the SlackPoint challenge
211+
:rtype: Response
212+
213+
"""
214+
130215
l = Leaderboard()
131216
payload = l.view_leaderboard()
132217
return jsonify(payload)

commands/createtask.py

+43-9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55

66
class CreateTask:
7+
"""
8+
This class handles the Create Task functionality.
9+
"""
10+
711
base_create_task_block_format = {
812
"type": "section",
913
"text": {
@@ -15,12 +19,29 @@ class CreateTask:
1519
greetings = ["Awesome", "Great", "Congratulations", "Well done", "Let's go"]
1620

1721
def __init__(self):
18-
self.payload = {
19-
"response_type": "ephemeral",
20-
"blocks": []
21-
}
22+
"""
23+
Constructor to initialize payload object
24+
25+
:param:
26+
:type:
27+
:raise:
28+
:return: None
29+
:rtype: None
30+
31+
"""
32+
self.payload = {"response_type": "ephemeral", "blocks": []}
2233

2334
def create_task_input_blocks(self):
35+
"""
36+
Create blocks list containing input fields for description, deadline, points of a task, along with a button to create the task
37+
38+
:param:
39+
:type:
40+
:raise:
41+
:return: Blocks list
42+
:rtype: list
43+
44+
"""
2445
block_description = {
2546
"type": "input",
2647
"element": {
@@ -76,10 +97,7 @@ def create_task_input_blocks(self):
7697
}
7798
block_actions_button = {
7899
"type": "button",
79-
"text": {
80-
"type": "plain_text",
81-
"text": "Create task"
82-
},
100+
"text": {"type": "plain_text", "text": "Create task"},
83101
"action_id": "create_action_button",
84102
}
85103
block_actions = {"type": "actions", "elements": []}
@@ -93,6 +111,20 @@ def create_task_input_blocks(self):
93111
return blocks
94112

95113
def create_task(self, desc, points, deadline):
114+
"""
115+
Creates a task in database and returns payload with success message along with the newly created Task ID
116+
117+
:param desc: Description of task
118+
:type desc: str
119+
:param points: Points of task
120+
:type points: int
121+
:param deadline: Deadline of task
122+
:type deadline: Date
123+
:raise:
124+
:return: Blocks list of response payload
125+
:rtype: list
126+
127+
"""
96128
# DB call to add task, returns id
97129
task = Task()
98130
task.description = desc
@@ -113,6 +145,8 @@ def create_task(self, desc, points, deadline):
113145
db.session.commit()
114146

115147
response = deepcopy(self.base_create_task_block_format)
116-
response["text"]["text"] = response["text"]["text"].format(greeting=random.choice(self.greetings), id=id)
148+
response["text"]["text"] = response["text"]["text"].format(
149+
greeting=random.choice(self.greetings), id=id
150+
)
117151
self.payload["blocks"].append(response)
118152
return self.payload["blocks"]

commands/help.py

+34
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33

44
class Help:
5+
"""
6+
This class handles the Help functionality.
7+
"""
8+
59
commands_dictionary = {}
610

711
command_help = {
@@ -10,6 +14,16 @@ class Help:
1014
}
1115

1216
def __init__(self):
17+
"""
18+
Constructor to initialize command dictionary and payload object
19+
20+
:param:
21+
:type:
22+
:raise:
23+
:return: None
24+
:rtype: None
25+
26+
"""
1327
self.commands_dictionary["createtask"] = [
1428
"*Create Task*",
1529
">To create a task, just try the command */create-task* and you would receive a message from Slack to fill out the details of the task.\n>Enter the description, deadline and the points of the task.\n>For example:\n>*Description*: Hey! This is my new task\n>*Deadline*: 12/31/2022 (just select a date from the date picker)\n>*Points*: 5 (select a point from 1 to 5)\n>And that's it! You should receive a reply from Slack with the generated *Task ID*.",
@@ -38,13 +52,33 @@ def __init__(self):
3852
self.payload = {"response_type": "ephemeral", "blocks": []}
3953

4054
def help_all(self):
55+
"""
56+
Creates a payload with the help details for all commands
57+
58+
:param:
59+
:type:
60+
:raise:
61+
:return: Payload object containing helper details of all commands
62+
:rtype: dict[str, Any]
63+
64+
"""
4165
response_payload = deepcopy(self.payload)
4266
for name in self.commands_dictionary.keys():
4367
blocks = self.help(name)
4468
response_payload["blocks"].extend(blocks)
4569
return response_payload
4670

4771
def help(self, command_name):
72+
"""
73+
Creates a payload blocks for particular command
74+
75+
:param command_name: Command name
76+
:type command_name: str
77+
:raise:
78+
:return: Blocks list containing details of a particular command provided in parameter
79+
:rtype: list
80+
81+
"""
4882
blocks = []
4983
command_name_block = deepcopy(self.command_help)
5084
command_help_desc_block = deepcopy(self.command_help)

commands/leaderboard.py

+24
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,39 @@
55

66

77
class Leaderboard:
8+
"""
9+
This class handles the Create Leaderboard functionality.
10+
"""
11+
812
base_leaderboard_block_format = {
913
"type": "section",
1014
"text": {"type": "mrkdwn", "text": "{pos}. <@{userid}> has {points} points!"},
1115
}
1216

1317
def __init__(self):
18+
"""
19+
Constructor to initialize payload object
20+
21+
:param:
22+
:type:
23+
:raise:
24+
:return: None
25+
:rtype: None
26+
27+
"""
1428
self.payload = {"response_type": "ephemeral", "blocks": []}
1529

1630
def view_leaderboard(self, top_k: int = 5) -> dict:
31+
"""
32+
Generates leaderboard according to the highest points scorers, returns top five contenders from DB
33+
34+
:param top_k: Provision to generate top k contenders in leaderboard, default value: 5
35+
:type top_k: int
36+
:raise:
37+
:return: Payload object containing details about the top 5 contenders of SlackPoint
38+
:rtype: dict[str, Any]
39+
40+
"""
1741
top_5_leaderboard = (
1842
Assignment.query.join(Task)
1943
.join(User)

0 commit comments

Comments
 (0)