|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | import contextlib |
4 | | -import re |
5 | 4 | from collections.abc import Iterable |
6 | 5 | from functools import partial |
7 | 6 | from operator import attrgetter |
8 | 7 | from textwrap import dedent |
9 | | -from typing import Literal, NamedTuple, TYPE_CHECKING, get_args |
| 8 | +from typing import NamedTuple, TYPE_CHECKING, get_args |
10 | 9 |
|
11 | 10 | from discord import AllowedMentions, HTTPException, Interaction, Message, NotFound, Reaction, User, enums, ui |
12 | 11 | from discord.ext.commands import Cog, Command, Context, Converter, command, guild_only |
|
19 | 18 | from bot.decorators import redirect_output |
20 | 19 | from bot.exts.filtering._filter_lists.extension import TXT_LIKE_FILES |
21 | 20 | from bot.exts.help_channels._channel import is_help_forum_post |
| 21 | +from bot.exts.utils.snekbox._constants import ( |
| 22 | + ANSI_REGEX, |
| 23 | + ESCAPE_REGEX, |
| 24 | + MAX_OUTPUT_BLOCK_CHARS, |
| 25 | + MAX_OUTPUT_BLOCK_LINES, |
| 26 | + NO_SNEKBOX_CATEGORIES, |
| 27 | + NO_SNEKBOX_CHANNELS, |
| 28 | + REDO_EMOJI, |
| 29 | + REDO_TIMEOUT, |
| 30 | + SNEKBOX_ROLES, |
| 31 | + SupportedPythonVersions, |
| 32 | +) |
22 | 33 | from bot.exts.utils.snekbox._eval import EvalJob, EvalResult |
23 | 34 | from bot.exts.utils.snekbox._io import FileAttachment |
24 | 35 | from bot.log import get_logger |
|
29 | 40 |
|
30 | 41 | log = get_logger(__name__) |
31 | 42 |
|
32 | | -ANSI_REGEX = re.compile(r"\N{ESC}\[[0-9;:]*m") |
33 | | -ESCAPE_REGEX = re.compile("[`\u202E\u200B]{3,}") |
34 | | - |
35 | 43 | # The timeit command should only output the very last line, so all other output should be suppressed. |
36 | 44 | # This will be used as the setup code along with any setup code provided. |
37 | 45 | TIMEIT_SETUP_WRAPPER = """ |
@@ -74,21 +82,6 @@ def print_last_line(): |
74 | 82 | {setup} |
75 | 83 | """ |
76 | 84 |
|
77 | | -# Max to display in a codeblock before sending to a paste service |
78 | | -# This also applies to text files |
79 | | -MAX_OUTPUT_BLOCK_LINES = 10 |
80 | | -MAX_OUTPUT_BLOCK_CHARS = 1000 |
81 | | - |
82 | | -# The Snekbox commands' whitelists and blacklists. |
83 | | -NO_SNEKBOX_CHANNELS = (Channels.python_general,) |
84 | | -NO_SNEKBOX_CATEGORIES = () |
85 | | -SNEKBOX_ROLES = (Roles.helpers, Roles.moderators, Roles.admins, Roles.owners, Roles.python_community, Roles.partners) |
86 | | - |
87 | | -REDO_EMOJI = "\U0001f501" # :repeat: |
88 | | -REDO_TIMEOUT = 30 |
89 | | - |
90 | | -SupportedPythonVersions = Literal["3.14", "3.13", "3.13t"] |
91 | | - |
92 | 85 | class FilteredFiles(NamedTuple): |
93 | 86 | allowed: list[FileAttachment] |
94 | 87 | blocked: list[FileAttachment] |
|
0 commit comments