From c0823236d20e801550fccdbb021d8aabb56d59c0 Mon Sep 17 00:00:00 2001 From: Amrou Bellalouna Date: Thu, 18 Aug 2022 16:58:08 +0100 Subject: add collection of keywords per rule In reference to issue #2108, this commit aims to add an initial set of keywords per rule. These keywords will be later in the "rule" bot command in order to make rule identification easier --- pydis_site/apps/api/views.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'pydis_site') diff --git a/pydis_site/apps/api/views.py b/pydis_site/apps/api/views.py index ad2d948e..f96d6a8d 100644 --- a/pydis_site/apps/api/views.py +++ b/pydis_site/apps/api/views.py @@ -124,35 +124,44 @@ class RulesView(APIView): return Response([ ( - f"Follow the {pydis_coc}." + f"Follow the {pydis_coc}.", + {"coc", "conduct", "code"} ), ( - f"Follow the {discord_community_guidelines} and {discord_tos}." + f"Follow the {discord_community_guidelines} and {discord_tos}.", + {"guidelines", "discord_tos"} ), ( - "Respect staff members and listen to their instructions." + "Respect staff members and listen to their instructions.", + {"staff", "instructions"} ), ( "Use English to the best of your ability. " - "Be polite if someone speaks English imperfectly." + "Be polite if someone speaks English imperfectly.", + {"english", "language"} ), ( "Do not provide or request help on projects that may break laws, " - "breach terms of services, or are malicious or inappropriate." + "breach terms of services, or are malicious or inappropriate.", + {"infraction", "tos", "breach", "malicious", "inappropriate"} ), ( - "Do not post unapproved advertising." + "Do not post unapproved advertising.", + {"ads", "advertising"} ), ( "Keep discussions relevant to the channel topic. " - "Each channel's description tells you the topic." + "Each channel's description tells you the topic.", + {"off-topic", "topic", "relevance"} ), ( "Do not help with ongoing exams. When helping with homework, " - "help people learn how to do the assignment without doing it for them." + "help people learn how to do the assignment without doing it for them.", + {"exams", "assignment", "assignments", "homework"} ), ( - "Do not offer or ask for paid work of any kind." + "Do not offer or ask for paid work of any kind.", + {"work", "money"} ), ]) -- cgit v1.2.3 From a75ba77bc8b83af97decde6c5ac4317bb3b5253d Mon Sep 17 00:00:00 2001 From: Amrou Bellalouna Date: Sun, 18 Sep 2022 18:38:02 +0100 Subject: add docstrings explaining the values that the Rules view returns --- pydis_site/apps/api/views.py | 1 + 1 file changed, 1 insertion(+) (limited to 'pydis_site') diff --git a/pydis_site/apps/api/views.py b/pydis_site/apps/api/views.py index f96d6a8d..66f4b18c 100644 --- a/pydis_site/apps/api/views.py +++ b/pydis_site/apps/api/views.py @@ -100,6 +100,7 @@ class RulesView(APIView): # `format` here is the result format, we have a link format here instead. def get(self, request, format=None): # noqa: D102,ANN001,ANN201 + """Returns a list of our community rules coupled with their keywords.""" link_format = request.query_params.get('link_format', 'md') if link_format not in ('html', 'md'): raise ParseError( -- cgit v1.2.3 From 672ba65b02fb111235fd3b928d5c84ee8b59cc54 Mon Sep 17 00:00:00 2001 From: Amrou Bellalouna Date: Sun, 18 Sep 2022 18:43:05 +0100 Subject: add suggested keywords --- pydis_site/apps/api/views.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'pydis_site') diff --git a/pydis_site/apps/api/views.py b/pydis_site/apps/api/views.py index 66f4b18c..836f11ce 100644 --- a/pydis_site/apps/api/views.py +++ b/pydis_site/apps/api/views.py @@ -126,43 +126,43 @@ class RulesView(APIView): return Response([ ( f"Follow the {pydis_coc}.", - {"coc", "conduct", "code"} + ["coc", "conduct", "code"] ), ( f"Follow the {discord_community_guidelines} and {discord_tos}.", - {"guidelines", "discord_tos"} + ["discord", "guidelines", "discord_tos"] ), ( "Respect staff members and listen to their instructions.", - {"staff", "instructions"} + ["respect", "staff", "instructions"] ), ( "Use English to the best of your ability. " "Be polite if someone speaks English imperfectly.", - {"english", "language"} + ["english", "language"] ), ( "Do not provide or request help on projects that may break laws, " "breach terms of services, or are malicious or inappropriate.", - {"infraction", "tos", "breach", "malicious", "inappropriate"} + ["infraction", "tos", "breach", "malicious", "inappropriate"] ), ( "Do not post unapproved advertising.", - {"ads", "advertising"} + ["ad", "ads", "advert", "advertising"] ), ( "Keep discussions relevant to the channel topic. " "Each channel's description tells you the topic.", - {"off-topic", "topic", "relevance"} + ["off-topic", "topic", "relevance"] ), ( "Do not help with ongoing exams. When helping with homework, " "help people learn how to do the assignment without doing it for them.", - {"exams", "assignment", "assignments", "homework"} + ["exam", "exams", "assignment", "assignments", "homework"] ), ( "Do not offer or ask for paid work of any kind.", - {"work", "money"} + ["paid", "work", "money"] ), ]) -- cgit v1.2.3 From f07f03abd53789062045afb027ef2d5ecfd63f11 Mon Sep 17 00:00:00 2001 From: Amrou Bellalouna Date: Sun, 18 Sep 2022 18:44:33 +0100 Subject: make docstring more explicit about the returned content --- pydis_site/apps/api/views.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'pydis_site') diff --git a/pydis_site/apps/api/views.py b/pydis_site/apps/api/views.py index 836f11ce..f76a78ff 100644 --- a/pydis_site/apps/api/views.py +++ b/pydis_site/apps/api/views.py @@ -100,7 +100,12 @@ class RulesView(APIView): # `format` here is the result format, we have a link format here instead. def get(self, request, format=None): # noqa: D102,ANN001,ANN201 - """Returns a list of our community rules coupled with their keywords.""" + """ + Returns a list of our community rules coupled with their keywords. + + Each item in the returned list is a tuple with the rule as first item + and a list of keywords that match that rules as second item. + """ link_format = request.query_params.get('link_format', 'md') if link_format not in ('html', 'md'): raise ParseError( -- cgit v1.2.3 From 13ae666f0281c7dcfbbe79fdf431f28cd822ec19 Mon Sep 17 00:00:00 2001 From: Amrou Bellalouna Date: Sun, 18 Sep 2022 18:55:18 +0100 Subject: update the RulesView class' docstrings --- pydis_site/apps/api/views.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'pydis_site') diff --git a/pydis_site/apps/api/views.py b/pydis_site/apps/api/views.py index f76a78ff..3cb7e8bd 100644 --- a/pydis_site/apps/api/views.py +++ b/pydis_site/apps/api/views.py @@ -37,12 +37,15 @@ class RulesView(APIView): ## Routes ### GET /rules - Returns a JSON array containing the server's rules: + Returns a JSON array containing the server's rules + coupled with a list of keywords that will be used + when searching for particular rules upon using the + bot's `!rule` command >>> [ - ... "Eat candy.", - ... "Wake up at 4 AM.", - ... "Take your medicine." + ... ("Eat candy.", ["candy", "sweet"]), + ... ("Wake up at 4 AM.", ["wake_up", "early", "early_bird"]), + ... ("Take your medicine.", ["medicine", "health"]) ... ] Since some of the the rules require links, this view -- cgit v1.2.3 From 49909a3165344b0fdbd81300cc752327e08f0ff5 Mon Sep 17 00:00:00 2001 From: Amrou Bellalouna Date: Sun, 18 Sep 2022 18:57:16 +0100 Subject: replace sweet with "sweets" to refer more to candy --- pydis_site/apps/api/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pydis_site') diff --git a/pydis_site/apps/api/views.py b/pydis_site/apps/api/views.py index 3cb7e8bd..2c5343de 100644 --- a/pydis_site/apps/api/views.py +++ b/pydis_site/apps/api/views.py @@ -43,7 +43,7 @@ class RulesView(APIView): bot's `!rule` command >>> [ - ... ("Eat candy.", ["candy", "sweet"]), + ... ("Eat candy.", ["candy", "sweets"]), ... ("Wake up at 4 AM.", ["wake_up", "early", "early_bird"]), ... ("Take your medicine.", ["medicine", "health"]) ... ] -- cgit v1.2.3 From e6db60717efe799e0900ad6cf60f4962f1aef7a1 Mon Sep 17 00:00:00 2001 From: Amrou Bellalouna Date: Sun, 18 Sep 2022 19:11:36 +0100 Subject: restrict the RulesView docstrings to just what it does --- pydis_site/apps/api/views.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'pydis_site') diff --git a/pydis_site/apps/api/views.py b/pydis_site/apps/api/views.py index 2c5343de..9e5ad73c 100644 --- a/pydis_site/apps/api/views.py +++ b/pydis_site/apps/api/views.py @@ -38,9 +38,8 @@ class RulesView(APIView): ## Routes ### GET /rules Returns a JSON array containing the server's rules - coupled with a list of keywords that will be used - when searching for particular rules upon using the - bot's `!rule` command + and keywords relating to each rule. + Example response: >>> [ ... ("Eat candy.", ["candy", "sweets"]), -- cgit v1.2.3 From 7fd81a80049763f1dc71815da27d65ce4344a191 Mon Sep 17 00:00:00 2001 From: Amrou Bellalouna Date: Sun, 18 Sep 2022 22:18:50 +0100 Subject: replace parenthesis with square brackets since tuples are serialized are lists --- pydis_site/apps/api/views.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'pydis_site') diff --git a/pydis_site/apps/api/views.py b/pydis_site/apps/api/views.py index 9e5ad73c..34167a38 100644 --- a/pydis_site/apps/api/views.py +++ b/pydis_site/apps/api/views.py @@ -42,9 +42,9 @@ class RulesView(APIView): Example response: >>> [ - ... ("Eat candy.", ["candy", "sweets"]), - ... ("Wake up at 4 AM.", ["wake_up", "early", "early_bird"]), - ... ("Take your medicine.", ["medicine", "health"]) + ... ["Eat candy.", ["candy", "sweets"]], + ... ["Wake up at 4 AM.", ["wake_up", "early", "early_bird"]], + ... ["Take your medicine.", ["medicine", "health"]] ... ] Since some of the the rules require links, this view -- cgit v1.2.3