@@ -13,31 +13,31 @@ def validate(
13
13
enforce_type : EnforceType ,
14
14
message : discord .Message ,
15
15
arg : Literal ["any" , "only" , "none" ] = "any" ,
16
- ) -> tuple [Literal [False ], str ] | tuple [Literal [True ], None ]:
16
+ ) -> tuple [Literal [False ], str , str | None ] | tuple [Literal [True ], None , None ]:
17
17
"""Validate a message for the presence of content according to the specified arguments."""
18
18
19
19
has_content = bool (message .content )
20
20
only_content = not has_content and not (message .attachments or message .embeds )
21
21
22
22
if enforce_type == "always" and arg == "only" and not only_content :
23
- return (False , "Message must always contain only text content" )
23
+ return (False , "Message must always contain only text content" , None )
24
24
25
25
if enforce_type == "always" and arg == "any" and not has_content :
26
- return (False , "Message must always contain text content" )
26
+ return (False , "Message must always contain text content" , None )
27
27
28
28
if enforce_type == "always" and arg == "none" and has_content :
29
- return (False , "Message must always contain no text content" )
29
+ return (False , "Message must always contain no text content" , None )
30
30
31
31
if enforce_type == "never" and arg == "only" and only_content :
32
- return (False , "Message must never contain only text content" )
32
+ return (False , "Message must never contain only text content" , None )
33
33
34
34
if enforce_type == "never" and arg == "any" and has_content :
35
- return (False , "Message must never contain text content" )
35
+ return (False , "Message must never contain text content" , None )
36
36
37
37
if enforce_type == "never" and arg == "none" and not has_content :
38
- return (False , "Message must never contain no text content" )
38
+ return (False , "Message must never contain no text content" , None )
39
39
40
- return (True , None )
40
+ return (True , None , None )
41
41
42
42
@staticmethod
43
43
def validate_arg (arg : Literal ["any" , "only" , "none" ]) -> str | None :
@@ -53,7 +53,7 @@ def validate(
53
53
enforce_type : EnforceType ,
54
54
message : discord .Message ,
55
55
arg : tuple [int , int ],
56
- ):
56
+ ) -> tuple [ Literal [ False ], str , str | None ] | tuple [ Literal [ True ], None , None ] :
57
57
"""Validate a message for the presence of text content within the specified length range."""
58
58
59
59
if not isinstance (arg , tuple ) or len (arg ) != 2 :
@@ -77,15 +77,17 @@ def validate(
77
77
return (
78
78
False ,
79
79
f"Message must always contain text content within { min_length } -{ max_length } characters" ,
80
+ None ,
80
81
)
81
82
82
83
if enforce_type == "never" and (min_length <= content_length <= max_length ):
83
84
return (
84
85
False ,
85
86
f"Message must never contain text content within { min_length } -{ max_length } characters" ,
87
+ None ,
86
88
)
87
89
88
- return (True , None )
90
+ return (True , None , None )
89
91
90
92
@staticmethod
91
93
def validate_arg (arg : tuple [int | None , int | None ]) -> str | None :
@@ -113,7 +115,7 @@ def validate(
113
115
enforce_type : EnforceType ,
114
116
message : discord .Message ,
115
117
arg : Literal ["any" , "only" , "none" ],
116
- ) -> tuple [Literal [False ], str ] | tuple [Literal [True ], None ]:
118
+ ) -> tuple [Literal [False ], str , str | None ] | tuple [Literal [True ], None , None ]:
117
119
"""Validate a message for the presence of URLs according to the specified arguments."""
118
120
119
121
search_obj = tuple (re .finditer (URL_PATTERN , message .content ))
@@ -125,24 +127,24 @@ def validate(
125
127
no_urls = not any_urls
126
128
127
129
if enforce_type == "always" and arg == "only" and not only_urls :
128
- return (False , "Message must always contain only URLs" )
130
+ return (False , "Message must always contain only URLs" , None )
129
131
130
132
if enforce_type == "always" and arg == "any" and not any_urls :
131
- return (False , "Message must always contain at least one URL" )
133
+ return (False , "Message must always contain at least one URL" , None )
132
134
133
135
if enforce_type == "always" and arg == "none" and not no_urls :
134
- return (False , "Message must always contain no URLs" )
136
+ return (False , "Message must always contain no URLs" , None )
135
137
136
138
if enforce_type == "never" and arg == "only" and only_urls :
137
- return (False , "Message must never contain only URLs" )
139
+ return (False , "Message must never contain only URLs" , None )
138
140
139
141
if enforce_type == "never" and arg == "any" and any_urls :
140
- return (False , "Message must never contain at least one URL" )
142
+ return (False , "Message must never contain at least one URL" , None )
141
143
142
144
if enforce_type == "never" and arg == "none" and no_urls :
143
- return (False , "Message must never contain no URLs" )
145
+ return (False , "Message must never contain no URLs" , None )
144
146
145
- return (True , None )
147
+ return (True , None , None )
146
148
147
149
148
150
# Rule for validating VCS URLs
@@ -154,7 +156,7 @@ def validate(
154
156
enforce_type : EnforceType ,
155
157
message : discord .Message ,
156
158
arg : Literal ["any" , "all" , "none" ] = "any" ,
157
- ) -> tuple [Literal [False ], str ] | tuple [Literal [True ], None ]:
159
+ ) -> tuple [Literal [False ], str , str | None ] | tuple [Literal [True ], None , None ]:
158
160
"""Validate a message for the presence of VCS URLs according to the specified arguments."""
159
161
160
162
search_obj = tuple (re .finditer (URL_PATTERN , message .content or "" ))
@@ -164,24 +166,32 @@ def validate(
164
166
all_vcs_urls = not any (not is_vcs_url (link ) for link in links )
165
167
166
168
if enforce_type == "always" and arg == "all" and not all_vcs_urls :
167
- return (False , "Message must always contain only valid VCS URLs" )
169
+ return (False , "Message must always contain only valid VCS URLs" , None )
168
170
169
171
if enforce_type == "always" and arg == "any" and not any_vcs_urls :
170
- return (False , "Message must always contain at least one valid VCS URL" )
172
+ return (
173
+ False ,
174
+ "Message must always contain at least one valid VCS URL" ,
175
+ None ,
176
+ )
171
177
172
178
if enforce_type == "always" and arg == "none" and not no_vcs_urls :
173
- return (False , "Message must always contain no valid VCS URLs" )
179
+ return (False , "Message must always contain no valid VCS URLs" , None )
174
180
175
181
if enforce_type == "never" and arg == "all" and all_vcs_urls :
176
- return (False , "Message must never contain only valid VCS URLs" )
182
+ return (False , "Message must never contain only valid VCS URLs" , None )
177
183
178
184
if enforce_type == "never" and arg == "any" and any_vcs_urls :
179
- return (False , "Message must never contain at least one valid VCS URL" )
185
+ return (
186
+ False ,
187
+ "Message must never contain at least one valid VCS URL" ,
188
+ None ,
189
+ )
180
190
181
191
if enforce_type == "never" and arg == "none" and no_vcs_urls :
182
- return (False , "Message must never contain no valid VCS URLs" )
192
+ return (False , "Message must never contain no valid VCS URLs" , None )
183
193
184
- return (True , None )
194
+ return (True , None , None )
185
195
186
196
@staticmethod
187
197
def validate_arg (arg : Literal ["any" , "all" , "none" ]) -> str | None :
@@ -197,32 +207,32 @@ def validate(
197
207
enforce_type : EnforceType ,
198
208
message : discord .Message ,
199
209
arg : Literal ["any" , "only" , "none" ],
200
- ):
210
+ ) -> tuple [ Literal [ False ], str , str | None ] | tuple [ Literal [ True ], None , None ] :
201
211
"""Validate a message for the presence of attachments according to the specified arguments."""
202
212
203
213
any_attachments = bool (message .attachments )
204
214
only_attachments = any_attachments and not (message .content or message .embeds )
205
215
no_attachments = not any_attachments
206
216
207
217
if enforce_type == "always" and arg == "only" and not only_attachments :
208
- return (False , "Message must always contain only attachments" )
218
+ return (False , "Message must always contain only attachments" , None )
209
219
210
220
if enforce_type == "always" and arg == "any" and not any_attachments :
211
- return (False , "Message must always contain at least one attachment" )
221
+ return (False , "Message must always contain at least one attachment" , None )
212
222
213
223
if enforce_type == "always" and arg == "none" and not no_attachments :
214
- return (False , "Message must always contain no attachments" )
224
+ return (False , "Message must always contain no attachments" , None )
215
225
216
226
if enforce_type == "never" and arg == "only" and only_attachments :
217
- return (False , "Message must never contain only attachments" )
227
+ return (False , "Message must never contain only attachments" , None )
218
228
219
229
if enforce_type == "never" and arg == "any" and any_attachments :
220
- return (False , "Message must never contain at least one attachment" )
230
+ return (False , "Message must never contain at least one attachment" , None )
221
231
222
232
if enforce_type == "never" and arg == "none" and no_attachments :
223
- return (False , "Message must never contain no attachments" )
233
+ return (False , "Message must never contain no attachments" , None )
224
234
225
- return (True , None )
235
+ return (True , None , None )
226
236
227
237
228
238
class EmbedsRule (DiscordMessageRule , name = "embeds" ):
@@ -233,32 +243,32 @@ def validate(
233
243
enforce_type : EnforceType ,
234
244
message : discord .Message ,
235
245
arg : Literal ["any" , "only" , "none" ],
236
- ) -> tuple [Literal [False ], str ] | tuple [Literal [True ], None ]:
246
+ ) -> tuple [Literal [False ], str , str | None ] | tuple [Literal [True ], None , None ]:
237
247
"""Validate a message for the presence of embeds according to the specified arguments."""
238
248
239
249
any_embeds = bool (message .embeds )
240
250
only_embeds = any_embeds and not (message .content or message .attachments )
241
251
no_embeds = not any_embeds
242
252
243
253
if enforce_type == "always" and arg == "only" and not only_embeds :
244
- return (False , "Message must always contain only embeds" )
254
+ return (False , "Message must always contain only embeds" , None )
245
255
246
256
if enforce_type == "always" and arg == "any" and not any_embeds :
247
- return (False , "Message must always contain at least one embed" )
257
+ return (False , "Message must always contain at least one embed" , None )
248
258
249
259
if enforce_type == "always" and arg == "none" and not no_embeds :
250
- return (False , "Message must always contain no embeds" )
260
+ return (False , "Message must always contain no embeds" , None )
251
261
252
262
if enforce_type == "never" and arg == "only" and only_embeds :
253
- return (False , "Message must never contain only embeds" )
263
+ return (False , "Message must never contain only embeds" , None )
254
264
255
265
if enforce_type == "never" and arg == "any" and any_embeds :
256
- return (False , "Message must never contain at least one embed" )
266
+ return (False , "Message must never contain at least one embed" , None )
257
267
258
268
if enforce_type == "never" and arg == "none" and no_embeds :
259
- return (False , "Message must never contain no embeds" )
269
+ return (False , "Message must never contain no embeds" , None )
260
270
261
- return (True , None )
271
+ return (True , None , None )
262
272
263
273
264
274
RULE_MAPPING : dict [str , type [DiscordMessageRule ]] = {
0 commit comments