Skip to content

Commit e81b0f1

Browse files
committed
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.
1 parent 1344368 commit e81b0f1

File tree

3 files changed

+37
-21
lines changed

3 files changed

+37
-21
lines changed

bot/exts/utils/snekbox/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from bot.bot import Bot
2-
from bot.exts.utils.snekbox._cog import CodeblockConverter, Snekbox, SupportedPythonVersions
2+
from bot.exts.utils.snekbox._cog import CodeblockConverter, Snekbox
3+
from bot.exts.utils.snekbox._constants import SupportedPythonVersions
34
from bot.exts.utils.snekbox._eval import EvalJob, EvalResult
45

56
__all__ = ("CodeblockConverter", "EvalJob", "EvalResult", "Snekbox", "SupportedPythonVersions")

bot/exts/utils/snekbox/_cog.py

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
from __future__ import annotations
22

33
import contextlib
4-
import re
54
from collections.abc import Iterable
65
from functools import partial
76
from operator import attrgetter
87
from textwrap import dedent
9-
from typing import Literal, NamedTuple, TYPE_CHECKING, get_args
8+
from typing import NamedTuple, TYPE_CHECKING, get_args
109

1110
from discord import AllowedMentions, HTTPException, Interaction, Message, NotFound, Reaction, User, enums, ui
1211
from discord.ext.commands import Cog, Command, Context, Converter, command, guild_only
@@ -19,6 +18,18 @@
1918
from bot.decorators import redirect_output
2019
from bot.exts.filtering._filter_lists.extension import TXT_LIKE_FILES
2120
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+
)
2233
from bot.exts.utils.snekbox._eval import EvalJob, EvalResult
2334
from bot.exts.utils.snekbox._io import FileAttachment
2435
from bot.log import get_logger
@@ -29,9 +40,6 @@
2940

3041
log = get_logger(__name__)
3142

32-
ANSI_REGEX = re.compile(r"\N{ESC}\[[0-9;:]*m")
33-
ESCAPE_REGEX = re.compile("[`\u202E\u200B]{3,}")
34-
3543
# The timeit command should only output the very last line, so all other output should be suppressed.
3644
# This will be used as the setup code along with any setup code provided.
3745
TIMEIT_SETUP_WRAPPER = """
@@ -74,21 +82,6 @@ def print_last_line():
7482
{setup}
7583
"""
7684

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-
9285
class FilteredFiles(NamedTuple):
9386
allowed: list[FileAttachment]
9487
blocked: list[FileAttachment]
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import re
2+
from typing import Literal
3+
4+
from bot.constants import Channels, Roles
5+
6+
ANSI_REGEX = re.compile(r"\N{ESC}\[[0-9;:]*m")
7+
ESCAPE_REGEX = re.compile("[`\u202E\u200B]{3,}")
8+
9+
# Max to display in a codeblock before sending to a paste service
10+
# This also applies to text files
11+
MAX_OUTPUT_BLOCK_LINES = 10
12+
MAX_OUTPUT_BLOCK_CHARS = 1000
13+
14+
# The Snekbox commands' whitelists and blacklists.
15+
NO_SNEKBOX_CHANNELS = (Channels.python_general,)
16+
NO_SNEKBOX_CATEGORIES = ()
17+
SNEKBOX_ROLES = (Roles.helpers, Roles.moderators, Roles.admins, Roles.owners, Roles.python_community, Roles.partners)
18+
19+
REDO_EMOJI = "\U0001f501" # :repeat:
20+
REDO_TIMEOUT = 30
21+
22+
SupportedPythonVersions = Literal["3.14", "3.13", "3.13t"]

0 commit comments

Comments
 (0)