-
-
Notifications
You must be signed in to change notification settings - Fork 720
feat(silence): allow to silence threads #3122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Snipy7374
wants to merge
8
commits into
python-discord:main
Choose a base branch
from
Snipy7374:feat/silence
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+38
−23
Open
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c156036
allow silencing threads
Snipy7374 332bbbd
lint files
Snipy7374 352dd56
Update bot/exts/moderation/silence.py
Snipy7374 3eb787a
move logic blocks and try to fix typings
Snipy7374 23fd132
Merge branch 'feat/silence' of github.com:Snipy7374/python-discord-bo…
Snipy7374 b488e80
Update bot/exts/moderation/silence.py
Snipy7374 f19fc4a
fix typing issues and add log message when silencing a thread
Snipy7374 9035d90
Merge branch 'main' into feat/silence
Snipy7374 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -178,12 +178,6 @@ async def silence( | |
channel_info = f"#{channel} ({channel.id})" | ||
log.debug(f"{ctx.author} is silencing channel {channel_info}.") | ||
|
||
# Since threads don't have specific overrides, we cannot silence them individually. | ||
# The parent channel has to be muted or the thread should be archived. | ||
if isinstance(channel, Thread): | ||
await ctx.send(":x: Threads cannot be silenced.") | ||
return | ||
|
||
if not await self._set_silence_overwrites(channel, kick=kick): | ||
log.info(f"Tried to silence channel {channel_info} but the channel was already silenced.") | ||
await self.send_message(MSG_SILENCE_FAIL, ctx.channel, channel, alert_target=False) | ||
|
@@ -242,6 +236,12 @@ async def _set_silence_overwrites(self, channel: TextOrVoiceChannel, *, kick: bo | |
send_messages_in_threads=overwrite.send_messages_in_threads | ||
) | ||
|
||
elif isinstance(channel, Thread): | ||
if channel.id in self.scheduler: | ||
return False | ||
await channel.edit(locked=True) | ||
Snipy7374 marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the thread is already locked, this will just schedule an unlock in the set amount of time. Failing is probably better to keep consistent with how it behaves with text channels. |
||
return True | ||
|
||
else: | ||
role = self._verified_voice_role | ||
overwrite = channel.overwrites_for(role) | ||
|
@@ -297,6 +297,11 @@ async def _unsilence_wrapper(self, channel: TextOrVoiceChannel, ctx: Context | N | |
if isinstance(channel, VoiceChannel): | ||
overwrite = channel.overwrites_for(self._verified_voice_role) | ||
has_channel_overwrites = overwrite.speak is False | ||
|
||
elif isinstance(channel, Thread): | ||
await self.send_message(MSG_UNSILENCE_FAIL, msg_channel, channel, alert_target=False) | ||
return | ||
Snipy7374 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
else: | ||
overwrite = channel.overwrites_for(self._everyone_role) | ||
has_channel_overwrites = overwrite.send_messages is False or overwrite.add_reactions is False | ||
|
@@ -318,8 +323,11 @@ async def _unsilence(self, channel: TextOrVoiceChannel) -> bool: | |
it, cancel the task, and remove it from the notifier. Notify admins if it has a task but | ||
not cached overwrites. | ||
|
||
Return `True` if channel permissions were changed, `False` otherwise. | ||
Return `True` if channel was unsilenced, `False` otherwise. | ||
""" | ||
if isinstance(channel, Thread): | ||
return await self._unsilence_thread(channel) | ||
|
||
Snipy7374 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# Get stored overwrites, and return if channel is unsilenced | ||
prev_overwrites = await self.previous_overwrites.get(channel.id) | ||
if channel.id not in self.scheduler and prev_overwrites is None: | ||
|
@@ -373,6 +381,25 @@ async def _unsilence(self, channel: TextOrVoiceChannel) -> bool: | |
|
||
return True | ||
|
||
async def _unsilence_thread(self, channel: Thread) -> bool: | ||
Snipy7374 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
Unsilence a thread. | ||
|
||
This function works the same as `_unsilence`, the only different behaviour regards unsilencing the channel | ||
which doesn't require an edit of the overwrites, instead we unlock the thread. | ||
|
||
Return `True` if the thread was unlocked, `False` otherwise. | ||
""" | ||
if channel.id not in self.scheduler: | ||
log.info(f"Tried to unsilence channel #{channel} ({channel.id}) but the channel was not silenced.") | ||
return False | ||
|
||
await channel.edit(locked=False) | ||
log.info(f"Unsilenced channel #{channel} ({channel.id}).") | ||
self.scheduler.cancel(channel.id) | ||
self.notifier.remove_channel(channel) | ||
return True | ||
|
||
@staticmethod | ||
async def _get_afk_channel(guild: Guild) -> VoiceChannel: | ||
"""Get a guild's AFK channel, or create one if it does not exist.""" | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.