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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
from rest_framework.exceptions import ParseError
from rest_framework.response import Response
from rest_framework.views import APIView
class HealthcheckView(APIView):
"""
Provides a simple view to check that the website is alive and well.
## Routes
### GET /healthcheck
Returns a simple JSON document showcasing whether the system is working:
>>> {
... 'status': 'ok'
... }
Seems to be.
## Authentication
Does not require any authentication nor permissions.
"""
authentication_classes = ()
permission_classes = ()
def get(self, request, format=None): # noqa
return Response({'status': 'ok'})
class RulesView(APIView):
"""
Return a list of the server's rules.
## Routes
### GET /rules
Returns a JSON array containing the server's rules:
>>> [
... "Eat candy.",
... "Wake up at 4 AM.",
... "Take your medicine."
... ]
Since some of the the rules require links, this view
gives you the option to return rules in either Markdown
or HTML format by specifying the `link_format` query parameter
as either `md` or `html`. Specifying a different value than
`md` or `html` will return 400.
## Authentication
Does not require any authentication nor permissions.
"""
authentication_classes = ()
permission_classes = ()
@staticmethod
def _format_link(description, link, target):
"""
Build the markup necessary to render `link` with `description`
as its description in the given `target` language.
Arguments:
description (str):
A textual description of the string. Represents the content
between the `<a>` tags in HTML, or the content between the
array brackets in Markdown.
link (str):
The resulting link that a user should be redirected to
upon clicking the generated element.
target (str):
One of `{'md', 'html'}`, denoting the target format that the
link should be rendered in.
Returns:
str:
The link, rendered appropriately for the given `target` format
using `description` as its textual description.
Raises:
ValueError:
If `target` is not `'md'` or `'html'`.
"""
if target == 'html':
return f'<a href="{link}">{description}</a>'
elif target == 'md':
return f'[{description}]({link})'
else:
raise ValueError(
f"Can only template links to `html` or `md`, got `{target}`"
)
# `format` here is the result format, we have a link format here instead.
def get(self, request, format=None): # noqa
link_format = request.query_params.get('link_format', 'md')
if link_format not in ('html', 'md'):
raise ParseError(
f"`format` must be `html` or `md`, got `{format}`."
)
discord_community_guidelines_link = self._format_link(
'Discord Community Guidelines',
'https://discordapp.com/guidelines',
link_format
)
channels_page_link = self._format_link(
'channels page',
'https://pythondiscord.com/about/channels',
link_format
)
google_translate_link = self._format_link(
'Google Translate',
'https://translate.google.com/',
link_format
)
return Response([
"Be polite, and do not spam.",
f"Follow the {discord_community_guidelines_link}.",
(
"Don't intentionally make other people uncomfortable - if "
"someone asks you to stop discussing something, you should stop."
),
(
"Be patient both with users asking "
"questions, and the users answering them."
),
(
"We will not help you with anything that might break a law or the "
"terms of service of any other community, site, service, or "
"otherwise - No piracy, brute-forcing, captcha circumvention, "
"sneaker bots, or anything else of that nature."
),
(
"Listen to and respect the staff members - we're "
"here to help, but we're all human beings."
),
(
"All discussion should be kept within the relevant "
"channels for the subject - See the "
f"{channels_page_link} for more information."
),
(
"This is an English-speaking server, so please speak English "
f"to the best of your ability - {google_translate_link} "
"should be fine if you're not sure."
),
(
"Keep all discussions safe for work - No gore, nudity, sexual "
"soliciting, references to suicide, or anything else of that nature"
),
(
"We do not allow advertisements for communities (including "
"other Discord servers) or commercial projects - Contact "
"us directly if you want to discuss a partnership!"
)
])
|