Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
raidensakura committed Apr 2, 2024
1 parent 605bb3f commit d7eb469
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions cogs/modmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from core.models import DMDisabled, PermissionLevel, SimilarCategoryConverter, getLogger
from core.paginator import EmbedPaginatorSession
from core.thread import Thread
from core.time import ShortTime, UserFriendlyTime, human_timedelta
from core.time import ShortTime, human_timedelta
from core.utils import *

logger = getLogger(__name__)
Expand Down Expand Up @@ -461,32 +461,35 @@ async def send_scheduled_close_message(self, ctx, after, silent=False):
async def close(
self,
ctx,
option: Optional[Literal["silent", "silently", "cancel"]] = "",
duration: Optional[ShortTime] = None,
option: Optional[Literal["silent", "silently", "cancel"]] = None,
*,
after: UserFriendlyTime = None,
message: Optional[str] = None,
):
"""
Close the current thread.
Close after a period of time:
- `{prefix}close in 5 hours`
- `{prefix}close 2m30s`
- `{prefix}close 5hours`
- `{prefix}close 3h2m30s`
Custom close messages:
- `{prefix}close 2 hours The issue has been resolved.`
- `{prefix}close We will contact you once we find out more.`
Close thread silently:
- `{prefix}close silent`
Silently close a thread (no message)
- `{prefix}close silently`
- `{prefix}close silently in 10m`
Close thread silently with a message:
- `{prefix}close silent The issue has been resolved.`
- `{prefix}close silently We will contact you once we find out more.`
Close after a period of time silently with a message:
`{prefix}close 3h10m silently Thread marked as inactive.`
Stop a thread from closing:
- `{prefix}close cancel`
"""

thread = ctx.thread

close_after = (after.dt - after.now).total_seconds() if after else 0
close_after = (duration.dt - duration.now).total_seconds() if duration else 0
silent = any(x == option for x in {"silent", "silently"})
cancel = option == "cancel"

Expand All @@ -504,12 +507,11 @@ async def close(

return await ctx.send(embed=embed)

message = after.arg if after else None
if self.bot.config["require_close_reason"] and message is None:
raise commands.BadArgument("Provide a reason for closing the thread.")

if after and after.dt > after.now:
await self.send_scheduled_close_message(ctx, after, silent)
if duration and duration.dt > duration.now:
await self.send_scheduled_close_message(ctx, duration, silent)

await thread.close(closer=ctx.author, after=close_after, message=message, silent=silent)

Expand Down

0 comments on commit d7eb469

Please sign in to comment.