Skip to content

Commit e538d96

Browse files
authored
Merge #770 - add a collection of keywords per rule
2 parents fb2a796 + 06b6b58 commit e538d96

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

pydis_site/apps/api/views.py

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,14 @@ class RulesView(APIView):
3737
3838
## Routes
3939
### GET /rules
40-
Returns a JSON array containing the server's rules:
40+
Returns a JSON array containing the server's rules
41+
and keywords relating to each rule.
42+
Example response:
4143
4244
>>> [
43-
... "Eat candy.",
44-
... "Wake up at 4 AM.",
45-
... "Take your medicine."
45+
... ["Eat candy.", ["candy", "sweets"]],
46+
... ["Wake up at 4 AM.", ["wake_up", "early", "early_bird"]],
47+
... ["Take your medicine.", ["medicine", "health"]]
4648
... ]
4749
4850
Since some of the the rules require links, this view
@@ -100,6 +102,12 @@ def _format_link(description: str, link: str, target: str) -> str:
100102

101103
# `format` here is the result format, we have a link format here instead.
102104
def get(self, request, format=None): # noqa: D102,ANN001,ANN201
105+
"""
106+
Returns a list of our community rules coupled with their keywords.
107+
108+
Each item in the returned list is a tuple with the rule as first item
109+
and a list of keywords that match that rules as second item.
110+
"""
103111
link_format = request.query_params.get('link_format', 'md')
104112
if link_format not in ('html', 'md'):
105113
raise ParseError(
@@ -124,35 +132,44 @@ def get(self, request, format=None): # noqa: D102,ANN001,ANN201
124132

125133
return Response([
126134
(
127-
f"Follow the {pydis_coc}."
135+
f"Follow the {pydis_coc}.",
136+
["coc", "conduct", "code"]
128137
),
129138
(
130-
f"Follow the {discord_community_guidelines} and {discord_tos}."
139+
f"Follow the {discord_community_guidelines} and {discord_tos}.",
140+
["discord", "guidelines", "discord_tos"]
131141
),
132142
(
133-
"Respect staff members and listen to their instructions."
143+
"Respect staff members and listen to their instructions.",
144+
["respect", "staff", "instructions"]
134145
),
135146
(
136147
"Use English to the best of your ability. "
137-
"Be polite if someone speaks English imperfectly."
148+
"Be polite if someone speaks English imperfectly.",
149+
["english", "language"]
138150
),
139151
(
140152
"Do not provide or request help on projects that may break laws, "
141-
"breach terms of services, or are malicious or inappropriate."
153+
"breach terms of services, or are malicious or inappropriate.",
154+
["infraction", "tos", "breach", "malicious", "inappropriate"]
142155
),
143156
(
144-
"Do not post unapproved advertising."
157+
"Do not post unapproved advertising.",
158+
["ad", "ads", "advert", "advertising"]
145159
),
146160
(
147161
"Keep discussions relevant to the channel topic. "
148-
"Each channel's description tells you the topic."
162+
"Each channel's description tells you the topic.",
163+
["off-topic", "topic", "relevance"]
149164
),
150165
(
151166
"Do not help with ongoing exams. When helping with homework, "
152-
"help people learn how to do the assignment without doing it for them."
167+
"help people learn how to do the assignment without doing it for them.",
168+
["exam", "exams", "assignment", "assignments", "homework"]
153169
),
154170
(
155-
"Do not offer or ask for paid work of any kind."
171+
"Do not offer or ask for paid work of any kind.",
172+
["paid", "work", "money"]
156173
),
157174
])
158175

0 commit comments

Comments
 (0)