aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Chris Lovering <[email protected]>2022-11-26 13:28:04 +0000
committerGravatar Chris Lovering <[email protected]>2022-11-26 13:43:24 +0000
commitdc99ba4125cd2cd95208b9972a30b3dcc90877b6 (patch)
tree7fe490245507014189fe487b9f4c3bb751fcd964
parentGet, and store, the help forum channel object on cog load (diff)
Consistantly refer to help posts as posts, not threads
-rw-r--r--bot/exts/help_channels/_channel.py82
-rw-r--r--bot/exts/help_channels/_cog.py12
2 files changed, 47 insertions, 47 deletions
diff --git a/bot/exts/help_channels/_channel.py b/bot/exts/help_channels/_channel.py
index 74d65107b..3a290bdfd 100644
--- a/bot/exts/help_channels/_channel.py
+++ b/bot/exts/help_channels/_channel.py
@@ -41,22 +41,22 @@ def is_help_forum_post(channel: discord.abc.GuildChannel) -> bool:
return getattr(channel, "parent_id", None) == constants.Channels.help_system_forum
-async def _close_help_thread(closed_thread: discord.Thread, closed_on: _stats.ClosingReason) -> None:
- """Close the help thread and record stats."""
+async def _close_help_post(closed_post: discord.Thread, closing_reason: _stats.ClosingReason) -> None:
+ """Close the help post and record stats."""
embed = discord.Embed(description=DORMANT_MSG)
- await closed_thread.send(embed=embed)
- await closed_thread.edit(archived=True, locked=True, reason="Locked a dormant help channel")
+ await closed_post.send(embed=embed)
+ await closed_post.edit(archived=True, locked=True, reason="Locked a dormant help post")
_stats.report_post_count()
- await _stats.report_complete_session(closed_thread, closed_on)
+ await _stats.report_complete_session(closed_post, closing_reason)
- poster = closed_thread.owner
- cooldown_role = closed_thread.guild.get_role(constants.Roles.help_cooldown)
+ poster = closed_post.owner
+ cooldown_role = closed_post.guild.get_role(constants.Roles.help_cooldown)
if poster is None:
# We can't include the owner ID/name here since the thread only contains None
log.info(
- f"Failed to remove cooldown role for owner of thread ({closed_thread.id}). "
+ f"Failed to remove cooldown role for owner of post ({closed_post.id}). "
f"The user is likely no longer on the server."
)
return
@@ -64,7 +64,7 @@ async def _close_help_thread(closed_thread: discord.Thread, closed_on: _stats.Cl
await members.handle_role_change(poster, poster.remove_roles, cooldown_role)
-async def send_opened_post_message(thread: discord.Thread) -> None:
+async def send_opened_post_message(post: discord.Thread) -> None:
"""Send the opener message in the new help post."""
embed = discord.Embed(
color=constants.Colours.bright_green,
@@ -72,24 +72,24 @@ async def send_opened_post_message(thread: discord.Thread) -> None:
)
embed.set_author(name=POST_TITLE)
embed.set_footer(text=POST_FOOTER)
- await thread.send(embed=embed)
+ await post.send(embed=embed)
-async def send_opened_post_dm(thread: discord.Thread) -> None:
+async def send_opened_post_dm(post: discord.Thread) -> None:
"""Send the opener a DM message with a jump link to their new post."""
embed = discord.Embed(
- title="Help channel opened",
- description=f"You opened {thread.mention}.",
+ title="Help post opened",
+ description=f"You opened {post.mention}.",
colour=constants.Colours.bright_green,
- timestamp=thread.created_at,
+ timestamp=post.created_at,
)
embed.set_thumbnail(url=constants.Icons.green_questionmark)
- message = thread.starter_message
+ message = post.starter_message
if not message:
try:
- message = await thread.fetch_message(thread.id)
+ message = await post.fetch_message(post.id)
except discord.HTTPException:
- log.warning(f"Could not fetch message for thread {thread.id}")
+ log.warning(f"Could not fetch message for post {post.id}")
return
formatted_message = textwrap.shorten(message.content, width=100, placeholder="...").strip()
@@ -105,21 +105,21 @@ async def send_opened_post_dm(thread: discord.Thread) -> None:
)
try:
- await thread.owner.send(embed=embed)
- log.trace(f"Sent DM to {thread.owner} ({thread.owner_id}) after posting in help forum.")
+ await post.owner.send(embed=embed)
+ log.trace(f"Sent DM to {post.owner} ({post.owner_id}) after posting in help forum.")
except discord.errors.Forbidden:
log.trace(
- f"Ignoring to send DM to {thread.owner} ({thread.owner_id}) after posting in help forum: DMs disabled.",
+ f"Ignoring to send DM to {post.owner} ({post.owner_id}) after posting in help forum: DMs disabled.",
)
-async def help_thread_opened(opened_thread: discord.Thread, *, reopen: bool = False) -> None:
+async def help_post_opened(opened_post: discord.Thread, *, reopen: bool = False) -> None:
"""Apply new post logic to a new help forum post."""
_stats.report_post_count()
- if not isinstance(opened_thread.owner, discord.Member):
- log.debug(f"{opened_thread.owner_id} isn't a member. Closing post.")
- await _close_help_thread(opened_thread, _stats.ClosingReason.CLEANUP)
+ 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)
return
# Discord sends the open event long before the thread is ready for actions in the API.
@@ -127,30 +127,30 @@ async def help_thread_opened(opened_thread: discord.Thread, *, reopen: bool = Fa
# We sleep here to try and delay our code enough so the thread is ready in the API.
await asyncio.sleep(2)
- await send_opened_post_dm(opened_thread)
+ await send_opened_post_dm(opened_post)
try:
- await opened_thread.starter_message.pin()
+ await opened_post.starter_message.pin()
except discord.HTTPException as e:
# Suppress if the message was not found, most likely deleted
if e.code != 10008:
raise e
- await send_opened_post_message(opened_thread)
+ await send_opened_post_message(opened_post)
- cooldown_role = opened_thread.guild.get_role(constants.Roles.help_cooldown)
- await members.handle_role_change(opened_thread.owner, opened_thread.owner.add_roles, cooldown_role)
+ cooldown_role = opened_post.guild.get_role(constants.Roles.help_cooldown)
+ await members.handle_role_change(opened_post.owner, opened_post.owner.add_roles, cooldown_role)
-async def help_thread_closed(closed_thread: discord.Thread) -> None:
+async def help_post_closed(closed_post: discord.Thread) -> None:
"""Apply archive logic to a manually closed help forum post."""
- await _close_help_thread(closed_thread, _stats.ClosingReason.COMMAND)
+ await _close_help_post(closed_post, _stats.ClosingReason.COMMAND)
-async def help_thread_archived(archived_thread: discord.Thread) -> None:
+async def help_post_archived(archived_post: discord.Thread) -> None:
"""Apply archive logic to an archived help forum post."""
- async for thread_update in archived_thread.guild.audit_logs(limit=50, action=discord.AuditLogAction.thread_update):
- if thread_update.target.id != archived_thread.id:
+ 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:
continue
# Don't apply close logic if the post was archived by the bot, as it
@@ -158,13 +158,13 @@ async def help_thread_archived(archived_thread: discord.Thread) -> None:
if thread_update.user.id == bot.instance.user.id:
return
- await _close_help_thread(archived_thread, _stats.ClosingReason.INACTIVE)
+ await _close_help_post(archived_post, _stats.ClosingReason.INACTIVE)
-async def help_thread_deleted(deleted_thread_event: discord.RawThreadDeleteEvent) -> None:
- """Record appropriate stats when a help thread is deleted."""
+async def help_post_deleted(deleted_post_event: discord.RawThreadDeleteEvent) -> None:
+ """Record appropriate stats when a help post is deleted."""
_stats.report_post_count()
- cached_thread = deleted_thread_event.thread
- if cached_thread and not cached_thread.archived:
- # If the thread is in the bot's cache, and it was not archived before deleting, report a complete session.
- await _stats.report_complete_session(cached_thread, _stats.ClosingReason.DELETED)
+ cached_post = deleted_post_event.thread
+ if cached_post and not cached_post.archived:
+ # If the post is in the bot's cache, and it was not archived before deleting, report a complete session.
+ await _stats.report_complete_session(cached_post, _stats.ClosingReason.DELETED)
diff --git a/bot/exts/help_channels/_cog.py b/bot/exts/help_channels/_cog.py
index 051532c74..742cf38dd 100644
--- a/bot/exts/help_channels/_cog.py
+++ b/bot/exts/help_channels/_cog.py
@@ -31,7 +31,7 @@ class HelpForum(commands.Cog):
self.help_forum_channel: discord.ForumChannel = None
async def cog_load(self) -> None:
- """Schedule the auto-archive check for all open posts."""
+ """Archive all idle open posts, schedule check for later for active open posts."""
log.trace("Initialising help forum cog.")
self.help_forum_channel = self.bot.get_channel(constants.Channels.help_system_forum)
@@ -58,7 +58,7 @@ class HelpForum(commands.Cog):
mod_alerts = self.bot.get_channel(constants.Channels.mod_alerts)
await mod_alerts.send(
f"<@&{constants.Roles.moderators}>\n"
- f"<@{post.owner_id}> ({post.owner_id}) opened the thread {post.mention} ({post.id}), "
+ f"<@{post.owner_id}> ({post.owner_id}) opened the post {post.mention} ({post.id}), "
"which triggered the token filter with its name!\n"
f"**Match:** {match.group()}"
)
@@ -79,7 +79,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_thread_closed(ctx.channel)
+ await _channel.help_post_closed(ctx.channel)
@help_forum_group.command(name="dm", root_aliases=("helpdm",))
async def help_dm_command(
@@ -125,7 +125,7 @@ class HelpForum(commands.Cog):
return
await self.post_with_disallowed_title_check(thread)
- await _channel.help_thread_opened(thread)
+ await _channel.help_post_opened(thread)
@commands.Cog.listener()
async def on_thread_update(self, before: discord.Thread, after: discord.Thread) -> None:
@@ -133,7 +133,7 @@ class HelpForum(commands.Cog):
if after.parent_id != self.help_forum_channel.id:
return
if not before.archived and after.archived:
- await _channel.help_thread_archived(after)
+ await _channel.help_post_archived(after)
if before.name != after.name:
await self.post_with_disallowed_title_check(after)
@@ -141,7 +141,7 @@ class HelpForum(commands.Cog):
async def on_raw_thread_delete(self, deleted_thread_event: discord.RawThreadDeleteEvent) -> None:
"""Defer application of new post logic for posts the help forum to the _channel helper."""
if deleted_thread_event.parent_id == self.help_forum_channel.id:
- await _channel.help_thread_deleted(deleted_thread_event)
+ await _channel.help_post_deleted(deleted_thread_event)
@commands.Cog.listener()
async def on_message(self, message: discord.Message) -> None: