aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bot/exts/help_channels/_channel.py46
-rw-r--r--bot/exts/help_channels/_cog.py10
-rw-r--r--bot/exts/help_channels/_stats.py1
-rw-r--r--bot/exts/utils/snekbox/_cog.py4
4 files changed, 41 insertions, 20 deletions
diff --git a/bot/exts/help_channels/_channel.py b/bot/exts/help_channels/_channel.py
index 9d76adf65..6a0c3264c 100644
--- a/bot/exts/help_channels/_channel.py
+++ b/bot/exts/help_channels/_channel.py
@@ -15,7 +15,6 @@ log = get_logger(__name__)
ASKING_GUIDE_URL = "https://pythondiscord.com/pages/asking-good-questions/"
BRANDING_REPO_RAW_URL = "https://raw.githubusercontent.com/python-discord/branding"
-POST_TITLE = "Python help channel"
NEW_POST_MSG = """
**Remember to:**
@@ -29,8 +28,8 @@ NEW_POST_FOOTER = f"Closes after a period of inactivity, or when you send {const
NEW_POST_ICON_URL = f"{BRANDING_REPO_RAW_URL}/main/icons/checkmark/green-checkmark-dist.png"
CLOSED_POST_MSG = f"""
-This help channel has been closed and it's no longer possible to send messages here. \
-If your question wasn't answered, feel free to create a new post in <#{constants.Channels.python_help}>. \
+This help channel has been closed. \
+Feel free to create a new post in <#{constants.Channels.python_help}>. \
To maximize your chances of getting a response, check out this guide on [asking good questions]({ASKING_GUIDE_URL}).
"""
CLOSED_POST_ICON_URL = f"{BRANDING_REPO_RAW_URL}/main/icons/zzz/zzz-dist.png"
@@ -42,13 +41,28 @@ def is_help_forum_post(channel: discord.abc.GuildChannel) -> bool:
return getattr(channel, "parent_id", None) == constants.Channels.python_help
-async def _close_help_post(closed_post: discord.Thread, closing_reason: _stats.ClosingReason) -> None:
+async def _close_help_post(
+ closed_post: discord.Thread,
+ closing_reason: _stats.ClosingReason,
+ scheduler: scheduling.Scheduler,
+) -> None:
"""Close the help post and record stats."""
# Get Thread with updated metadata (such as the title)
closed_post = await get_or_fetch_channel(bot.instance, closed_post.id)
embed = discord.Embed(description=CLOSED_POST_MSG)
- embed.set_author(name=f"{POST_TITLE} closed", icon_url=CLOSED_POST_ICON_URL)
+ close_title = "Python help channel closed"
+ if closing_reason == _stats.ClosingReason.CLEANUP:
+ close_title += " as OP left server"
+ elif closing_reason == _stats.ClosingReason.COMMAND:
+ close_title += f" with {constants.Bot.prefix}close"
+ elif closing_reason == _stats.ClosingReason.INACTIVE:
+ close_title += " for inactivity"
+ elif closing_reason == _stats.ClosingReason.NATIVE:
+ close_title += " using Discord native close action"
+
+
+ embed.set_author(name=close_title, icon_url=CLOSED_POST_ICON_URL)
message = ""
# Include a ping in the close message if no one else engages, to encourage them
@@ -72,6 +86,8 @@ async def _close_help_post(closed_post: discord.Thread, closing_reason: _stats.C
locked=True,
reason="Locked a closed help post",
)
+ if closed_post.id in scheduler:
+ scheduler.cancel(closed_post.id)
_stats.report_post_count()
await _stats.report_complete_session(closed_post, closing_reason)
@@ -83,19 +99,23 @@ async def send_opened_post_message(post: discord.Thread) -> None:
color=constants.Colours.bright_green,
description=NEW_POST_MSG,
)
- embed.set_author(name=f"{POST_TITLE} opened", icon_url=NEW_POST_ICON_URL)
+ embed.set_author(name="Python help channel opened", icon_url=NEW_POST_ICON_URL)
embed.set_footer(text=NEW_POST_FOOTER)
await post.send(embed=embed, content=post.owner.mention)
-async def help_post_opened(opened_post: discord.Thread, *, reopen: bool = False) -> None:
+async def help_post_opened(
+ opened_post: discord.Thread,
+ *,
+ scheduler: scheduling.Scheduler,
+) -> None:
"""Apply new post logic to a new help forum post."""
_stats.report_post_count()
bot.instance.stats.incr("help.claimed")
if not isinstance(opened_post.owner, discord.Member):
log.debug(f"{opened_post.owner_id} isn't a member. Closing post.")
- await _close_help_post(opened_post, _stats.ClosingReason.CLEANUP)
+ await _close_help_post(opened_post, _stats.ClosingReason.CLEANUP, scheduler)
return
try:
@@ -114,12 +134,12 @@ async def help_post_opened(opened_post: discord.Thread, *, reopen: bool = False)
await send_opened_post_message(opened_post)
-async def help_post_closed(closed_post: discord.Thread) -> None:
+async def help_post_closed(closed_post: discord.Thread, scheduler: scheduling.Scheduler) -> None:
"""Apply archive logic to a manually closed help forum post."""
- await _close_help_post(closed_post, _stats.ClosingReason.COMMAND)
+ await _close_help_post(closed_post, _stats.ClosingReason.COMMAND, scheduler)
-async def help_post_archived(archived_post: discord.Thread) -> None:
+async def help_post_archived(archived_post: discord.Thread, scheduler: scheduling.Scheduler) -> None:
"""Apply archive logic to an archived help forum post."""
async for thread_update in archived_post.guild.audit_logs(limit=50, action=discord.AuditLogAction.thread_update):
if thread_update.target.id != archived_post.id:
@@ -130,7 +150,7 @@ async def help_post_archived(archived_post: discord.Thread) -> None:
if thread_update.user.id == bot.instance.user.id:
return
- await _close_help_post(archived_post, _stats.ClosingReason.INACTIVE)
+ await _close_help_post(archived_post, _stats.ClosingReason.NATIVE, scheduler)
async def help_post_deleted(deleted_post_event: discord.RawThreadDeleteEvent) -> None:
@@ -194,7 +214,7 @@ async def maybe_archive_idle_post(post: discord.Thread, scheduler: scheduling.Sc
log.info(
f"#{post} ({post.id}) is idle past {closing_time} and will be archived. Reason: {closing_reason.value}"
)
- await _close_help_post(post, closing_reason)
+ await _close_help_post(post, closing_reason, scheduler)
return
if post.id in scheduler:
diff --git a/bot/exts/help_channels/_cog.py b/bot/exts/help_channels/_cog.py
index 0e0274255..9db66bb39 100644
--- a/bot/exts/help_channels/_cog.py
+++ b/bot/exts/help_channels/_cog.py
@@ -81,9 +81,7 @@ class HelpForum(commands.Cog):
# Don't use a discord.py check because the check needs to fail silently.
if await self.close_check(ctx):
log.info(f"Close command invoked by {ctx.author} in #{ctx.channel}.")
- await _channel.help_post_closed(ctx.channel)
- if ctx.channel.id in self.scheduler:
- self.scheduler.cancel(ctx.channel.id)
+ await _channel.help_post_closed(ctx.channel, self.scheduler)
@help_forum_group.command(name="title", root_aliases=("title",))
async def rename_help_post(self, ctx: commands.Context, *, title: str) -> None:
@@ -112,7 +110,7 @@ class HelpForum(commands.Cog):
if thread.parent_id != self.help_forum_channel.id:
return
- await _channel.help_post_opened(thread)
+ await _channel.help_post_opened(thread, scheduler=self.scheduler)
delay = min(constants.HelpChannels.deleted_idle_minutes, constants.HelpChannels.idle_minutes) * 60
self.scheduler.schedule_later(
@@ -127,7 +125,9 @@ class HelpForum(commands.Cog):
if after.parent_id != self.help_forum_channel.id:
return
if not before.archived and after.archived:
- await _channel.help_post_archived(after)
+ await _channel.help_post_archived(after, self.scheduler)
+ if after.id in self.scheduler:
+ self.scheduler.cancel(after.id)
@commands.Cog.listener()
async def on_raw_thread_delete(self, deleted_thread_event: discord.RawThreadDeleteEvent) -> None:
diff --git a/bot/exts/help_channels/_stats.py b/bot/exts/help_channels/_stats.py
index 6ca40139b..687ebc80c 100644
--- a/bot/exts/help_channels/_stats.py
+++ b/bot/exts/help_channels/_stats.py
@@ -16,6 +16,7 @@ class ClosingReason(Enum):
COMMAND = "command"
INACTIVE = "auto.inactive"
+ NATIVE = "auto.native"
DELETED = "auto.deleted"
CLEANUP = "auto.cleanup"
diff --git a/bot/exts/utils/snekbox/_cog.py b/bot/exts/utils/snekbox/_cog.py
index f13ede51a..9e635e18a 100644
--- a/bot/exts/utils/snekbox/_cog.py
+++ b/bot/exts/utils/snekbox/_cog.py
@@ -599,7 +599,7 @@ class Snekbox(Cog):
If multiple codeblocks are in a message, all of them will be joined and evaluated,
ignoring the text outside them.
- Currently only 3.12 version is supported.
+ The currently supported verisons are 3.12, 3.13, and 3.13t.
We've done our best to make this sandboxed, but do let us know if you manage to find an
issue with it!
@@ -635,7 +635,7 @@ class Snekbox(Cog):
If multiple formatted codeblocks are provided, the first one will be the setup code, which will
not be timed. The remaining codeblocks will be joined together and timed.
- Currently only 3.12 version is supported.
+ The currently supported verisons are 3.12, 3.13, and 3.13t.
We've done our best to make this sandboxed, but do let us know if you manage to find an
issue with it!