Skip to content

Commit a2787e8

Browse files
committed
thread_auto_close_silently + some fixes
1 parent f9781c3 commit a2787e8

File tree

4 files changed

+37
-9
lines changed

4 files changed

+37
-9
lines changed

CHANGELOG.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- `disable_recipient_thread_close` is removed, a new configuration variable `recipient_thread_close` replaces it which defaults to False.
1313
- Truthy and falsy values for binary configuration variables are now interpreted respectfully.
1414

15+
### Added
16+
17+
- `?sfw`, mark a thread as "safe for work", undos `?nsfw`.
18+
- New config variable, `thread_auto_close_silently`, when set to a truthy value, no message will be sent when thread is auto-closed.
19+
- New configuration variable `thread_self_closable_creation_footer` — the footer when `recipient_thread_close` is enabled.
20+
1521
### Changes
1622

1723
- `thread_auto_close_response` has a configurable variable `{timeout}`.
18-
- New configuration variable `thread_self_closable_creation_footer`, the footer when `recipient_thread_close` is enabled.
1924
- `?snippet` is now the default command name instead of `?snippets` (`?snippets` is still usable). This is to make this consistent with `?alias`/`?aliases`.
2025

2126
### Fixes
2227

2328
- `?notify` no longer carries over to the next thread.
2429
- `discord.NotFound` errors for `on_raw_reaction_add`.
2530
- `mod_typing` and `user_typing` will no longer show when user is blocked.
26-
27-
### Added
28-
29-
- `?sfw`, mark a thread as "safe for work", undos `?nsfw`.
31+
- Better `?block` usage message.
32+
- Resolves errors when message was sent by mods after thread is closed somehow.
3033

3134
### Internal
3235

cogs/modmail.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ async def blocked_whitelist(self, ctx, *, user: User = None):
917917

918918
return await ctx.send(embed=embed)
919919

920-
@commands.command()
920+
@commands.command(usage="[user] [duration] [close message]")
921921
@checks.has_permissions(PermissionLevel.MODERATOR)
922922
@trigger_typing
923923
async def block(
@@ -931,7 +931,7 @@ async def block(
931931
Leave `user` blank when this command is used within a
932932
thread channel to block the current recipient.
933933
`user` may be a user ID, mention, or name.
934-
`after` may be a simple "human-readable" time text. See `{prefix}help close` for examples.
934+
`duration` may be a simple "human-readable" time text. See `{prefix}help close` for examples.
935935
"""
936936

937937
reason = ""

core/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class ConfigManager:
4242
"blocked_emoji": "🚫",
4343
"close_emoji": "🔒",
4444
"recipient_thread_close": False,
45+
"thread_auto_close_silently": False,
4546
"thread_auto_close": 0,
4647
"thread_auto_close_response": "This thread has been closed automatically due to inactivity after {timeout}.",
4748
"thread_creation_response": "The staff team will get back to you as soon as possible.",
@@ -106,6 +107,7 @@ class ConfigManager:
106107
"mod_typing",
107108
"reply_without_command",
108109
"recipient_thread_close",
110+
"thread_auto_close_silently"
109111
}
110112

111113
defaults = {**public_keys, **private_keys, **protected_keys}

core/thread.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,11 @@ async def close(
232232
async def _close(
233233
self, closer, silent=False, delete_channel=True, message=None, scheduled=False
234234
):
235-
self.manager.cache.pop(self.id)
235+
try:
236+
self.manager.cache.pop(self.id)
237+
except KeyError:
238+
logger.warning('Thread already closed.', exc_info=True)
239+
return
236240

237241
await self.cancel_closure(all=True)
238242

@@ -396,6 +400,21 @@ async def _restart_close_timer(self):
396400
reset_time = datetime.utcnow() + timedelta(seconds=seconds)
397401
human_time = human_timedelta(dt=reset_time)
398402

403+
try:
404+
thread_auto_close_silently = strtobool(
405+
self.bot.config["thread_auto_close_silently"]
406+
)
407+
except ValueError:
408+
thread_auto_close_silently = self.bot.config.remove("thread_auto_close_silently")
409+
410+
if thread_auto_close_silently:
411+
return await self.close(
412+
closer=self.bot.user,
413+
silent=True,
414+
after=int(seconds),
415+
auto_close=True,
416+
)
417+
399418
# Grab message
400419
close_message = self.bot.config["thread_auto_close_response"].format(
401420
timeout=human_time
@@ -674,7 +693,11 @@ async def send(
674693
# noinspection PyUnresolvedReferences,PyDunderSlots
675694
embed.color = self.bot.recipient_color # pylint: disable=E0237
676695

677-
await destination.trigger_typing()
696+
try:
697+
await destination.trigger_typing()
698+
except discord.NotFound:
699+
logger.warning('Channel not found.', exc_info=True)
700+
return
678701

679702
if not from_mod and not note:
680703
mentions = self.get_notifications()

0 commit comments

Comments
 (0)