-
-
Notifications
You must be signed in to change notification settings - Fork 675
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
feat(silence): allow to silence threads #3122
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! I haven't tested the code yet, but here are some comments.
A few more things I'd like to point out:
- I'm not sure what you mean by "the annotations were wrong before". Could you elaborate a bit on that?
Thread
isn't a subclass ofTextChannel
soTextOrVoiceChannel
should be updated accordingly. Renaming it to something likeSilencableChannel
also seems reasonable.- The existing method names sound pretty inconsistent. This isn't your fault, but maybe they could be updated while we're at it?
Co-authored-by: Daniel Gu <daniel.gu25@stu.dulwich.org>
…t into feat/silence
Sorry for the delay, i was busy doing the code jam. I tried to fix the typing issues but a lot of other errors persist from previous code, for example see this, a lot of things are unknown, also the Context annotation always doesn't have the bot type var. I'm using pyright in strict mode so maybe that's why but yeah, there are a lot of typing errors across all the codebase. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there! Just a few more nitpicks to go.
Co-authored-by: Daniel Gu <daniel.gu25@stu.dulwich.org>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I finally got around to testing this change and found an edge case: (un)silencing when the thread is already (un)locked.
@@ -242,6 +242,11 @@ async def _set_silence_overwrites(self, channel: TextOrVoiceChannel, *, kick: bo | |||
send_messages_in_threads=overwrite.send_messages_in_threads | |||
) | |||
|
|||
elif isinstance(channel, Thread): | |||
log.info(f"Silencing thread #{channel.parent}/{channel} ({channel.parent.id}/{channel.id}).") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, logging this is handled in _silence()
instead so this wasn't necessary.
log.info(f"Silencing thread #{channel.parent}/{channel} ({channel.parent.id}/{channel.id}).") |
@@ -242,6 +242,11 @@ async def _set_silence_overwrites(self, channel: TextOrVoiceChannel, *, kick: bo | |||
send_messages_in_threads=overwrite.send_messages_in_threads | |||
) | |||
|
|||
elif isinstance(channel, Thread): | |||
log.info(f"Silencing thread #{channel.parent}/{channel} ({channel.parent.id}/{channel.id}).") | |||
await channel.edit(locked=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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.
@@ -331,6 +340,12 @@ async def _unsilence(self, channel: TextOrVoiceChannel) -> bool: | |||
role = self._everyone_role | |||
overwrite = channel.overwrites_for(role) | |||
permissions = "`Send Messages` and `Add Reactions`" | |||
elif isinstance(channel, Thread): | |||
await channel.edit(locked=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above: if the thread was manually unlocked before the scheduled time, there won't be any indication of it.
The code might not be that clean, also i think that the annotations were wrong before, now they are surely wrong, do you care about them?
Also, since this is my first contribution to this repository, let me know if i missed anything out.