diff options
author | 2025-10-09 14:45:23 +0100 | |
---|---|---|
committer | 2025-10-09 14:48:59 +0100 | |
commit | e81b0f13ef0cfeb11a53d52c6b43c976184235f7 (patch) | |
tree | 5bfa42b6c4d2583209eaae202d71a7131596c504 | |
parent | Remove notice about 3.14 being pre-release (diff) |
Move snekbox operational and typing constants to a new file
This will allow all other utility files within the snekbox cog to access
types such as `SupportedPythonVersions` without causing circular import
issues.
-rw-r--r-- | bot/exts/utils/snekbox/__init__.py | 3 | ||||
-rw-r--r-- | bot/exts/utils/snekbox/_cog.py | 33 | ||||
-rw-r--r-- | bot/exts/utils/snekbox/_constants.py | 22 |
3 files changed, 37 insertions, 21 deletions
diff --git a/bot/exts/utils/snekbox/__init__.py b/bot/exts/utils/snekbox/__init__.py index fa91d0d6f..b6ad82c7e 100644 --- a/bot/exts/utils/snekbox/__init__.py +++ b/bot/exts/utils/snekbox/__init__.py @@ -1,5 +1,6 @@ from bot.bot import Bot -from bot.exts.utils.snekbox._cog import CodeblockConverter, Snekbox, SupportedPythonVersions +from bot.exts.utils.snekbox._cog import CodeblockConverter, Snekbox +from bot.exts.utils.snekbox._constants import SupportedPythonVersions from bot.exts.utils.snekbox._eval import EvalJob, EvalResult __all__ = ("CodeblockConverter", "EvalJob", "EvalResult", "Snekbox", "SupportedPythonVersions") diff --git a/bot/exts/utils/snekbox/_cog.py b/bot/exts/utils/snekbox/_cog.py index f8651eda5..5fb160a5f 100644 --- a/bot/exts/utils/snekbox/_cog.py +++ b/bot/exts/utils/snekbox/_cog.py @@ -1,12 +1,11 @@ from __future__ import annotations import contextlib -import re from collections.abc import Iterable from functools import partial from operator import attrgetter from textwrap import dedent -from typing import Literal, NamedTuple, TYPE_CHECKING, get_args +from typing import NamedTuple, TYPE_CHECKING, get_args from discord import AllowedMentions, HTTPException, Interaction, Message, NotFound, Reaction, User, enums, ui from discord.ext.commands import Cog, Command, Context, Converter, command, guild_only @@ -19,6 +18,18 @@ from bot.constants import BaseURLs, Channels, Emojis, MODERATION_ROLES, Roles, U from bot.decorators import redirect_output from bot.exts.filtering._filter_lists.extension import TXT_LIKE_FILES from bot.exts.help_channels._channel import is_help_forum_post +from bot.exts.utils.snekbox._constants import ( + ANSI_REGEX, + ESCAPE_REGEX, + MAX_OUTPUT_BLOCK_CHARS, + MAX_OUTPUT_BLOCK_LINES, + NO_SNEKBOX_CATEGORIES, + NO_SNEKBOX_CHANNELS, + REDO_EMOJI, + REDO_TIMEOUT, + SNEKBOX_ROLES, + SupportedPythonVersions, +) from bot.exts.utils.snekbox._eval import EvalJob, EvalResult from bot.exts.utils.snekbox._io import FileAttachment from bot.log import get_logger @@ -29,9 +40,6 @@ if TYPE_CHECKING: log = get_logger(__name__) -ANSI_REGEX = re.compile(r"\N{ESC}\[[0-9;:]*m") -ESCAPE_REGEX = re.compile("[`\u202E\u200B]{3,}") - # The timeit command should only output the very last line, so all other output should be suppressed. # This will be used as the setup code along with any setup code provided. TIMEIT_SETUP_WRAPPER = """ @@ -74,21 +82,6 @@ if not hasattr(sys, "_setup_finished"): {setup} """ -# Max to display in a codeblock before sending to a paste service -# This also applies to text files -MAX_OUTPUT_BLOCK_LINES = 10 -MAX_OUTPUT_BLOCK_CHARS = 1000 - -# The Snekbox commands' whitelists and blacklists. -NO_SNEKBOX_CHANNELS = (Channels.python_general,) -NO_SNEKBOX_CATEGORIES = () -SNEKBOX_ROLES = (Roles.helpers, Roles.moderators, Roles.admins, Roles.owners, Roles.python_community, Roles.partners) - -REDO_EMOJI = "\U0001f501" # :repeat: -REDO_TIMEOUT = 30 - -SupportedPythonVersions = Literal["3.14", "3.13", "3.13t"] - class FilteredFiles(NamedTuple): allowed: list[FileAttachment] blocked: list[FileAttachment] diff --git a/bot/exts/utils/snekbox/_constants.py b/bot/exts/utils/snekbox/_constants.py new file mode 100644 index 000000000..efcb47c33 --- /dev/null +++ b/bot/exts/utils/snekbox/_constants.py @@ -0,0 +1,22 @@ +import re +from typing import Literal + +from bot.constants import Channels, Roles + +ANSI_REGEX = re.compile(r"\N{ESC}\[[0-9;:]*m") +ESCAPE_REGEX = re.compile("[`\u202E\u200B]{3,}") + +# Max to display in a codeblock before sending to a paste service +# This also applies to text files +MAX_OUTPUT_BLOCK_LINES = 10 +MAX_OUTPUT_BLOCK_CHARS = 1000 + +# The Snekbox commands' whitelists and blacklists. +NO_SNEKBOX_CHANNELS = (Channels.python_general,) +NO_SNEKBOX_CATEGORIES = () +SNEKBOX_ROLES = (Roles.helpers, Roles.moderators, Roles.admins, Roles.owners, Roles.python_community, Roles.partners) + +REDO_EMOJI = "\U0001f501" # :repeat: +REDO_TIMEOUT = 30 + +SupportedPythonVersions = Literal["3.14", "3.13", "3.13t"] |