Skip to content

Commit

Permalink
Merge branch 'main' into swfarnsworth/fix-auto-upload
Browse files Browse the repository at this point in the history
  • Loading branch information
swfarnsworth authored Feb 8, 2025
2 parents e3dd43a + c6fd024 commit 1d254d6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
10 changes: 4 additions & 6 deletions bot/exts/help_channels/_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ async def _close_help_post(
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)
close_title = "Python help channel closed"
if closing_reason == _stats.ClosingReason.CLEANUP:
Expand Down Expand Up @@ -192,10 +189,11 @@ async def get_closing_time(post: discord.Thread) -> tuple[arrow.Arrow, _stats.Cl
return time, _stats.ClosingReason.INACTIVE


async def maybe_archive_idle_post(post: discord.Thread, scheduler: scheduling.Scheduler) -> None:
async def maybe_archive_idle_post(post_id: int, scheduler: scheduling.Scheduler) -> None:
"""Archive the `post` if idle, or schedule the archive for later if still active."""
try:
await get_or_fetch_channel(bot.instance, post.id)
# Fetch the post again, to ensure we have the latest info
post = await get_or_fetch_channel(bot.instance, post_id)
except discord.HTTPException:
log.trace(f"Not closing missing post #{post} ({post.id}).")
return
Expand Down Expand Up @@ -223,4 +221,4 @@ async def maybe_archive_idle_post(post: discord.Thread, scheduler: scheduling.Sc
delay = (closing_time - arrow.utcnow()).seconds
log.info(f"#{post} ({post.id}) is still active; scheduling it to be archived after {delay} seconds.")

scheduler.schedule_later(delay, post.id, maybe_archive_idle_post(post, scheduler))
scheduler.schedule_later(delay, post.id, maybe_archive_idle_post(post.id, scheduler))
4 changes: 2 additions & 2 deletions bot/exts/help_channels/_cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async def check_all_open_posts_have_close_task(self) -> None:
"""Check that each open help post has a scheduled task to close, adding one if not."""
for post in self.help_forum_channel.threads:
if post.id not in self.scheduler:
await _channel.maybe_archive_idle_post(post, self.scheduler)
await _channel.maybe_archive_idle_post(post.id, self.scheduler)

async def close_check(self, ctx: commands.Context) -> bool:
"""Return True if the channel is a help post, and the user is the claimant or has a whitelisted role."""
Expand Down Expand Up @@ -116,7 +116,7 @@ async def new_post_listener(self, message: discord.Message) -> None:
self.scheduler.schedule_later(
delay,
thread.id,
_channel.maybe_archive_idle_post(thread, self.scheduler)
_channel.maybe_archive_idle_post(thread.id, self.scheduler)
)

@commands.Cog.listener()
Expand Down

0 comments on commit 1d254d6

Please sign in to comment.