Skip to content

Whitelist a thread when its parent is whitelisted#1231

Merged
shtlrs merged 2 commits into
python-discord:mainfrom
shtlrs:whitelist-threads-with-their-parents
Mar 10, 2023
Merged

Whitelist a thread when its parent is whitelisted#1231
shtlrs merged 2 commits into
python-discord:mainfrom
shtlrs:whitelist-threads-with-their-parents

Conversation

@shtlrs
Copy link
Copy Markdown
Contributor

@shtlrs shtlrs commented Mar 10, 2023

Currently, we can't execute commands in threads if they're not whitelisted.
The problem is, we can't have a thread id in advance.

This adds the possibility to do that when the parent of the thread is whitelisted (Just like the case of help forum channels)

Context:
This is needed in order of achieving #1230

Comment thread bot/utils/checks.py Outdated
channels = tuple(channels) + (redirect,)

# If it's a thread, and its parent is whitelisted, we whitelist the thread as well
if channels and isinstance(ctx.channel, Thread) and ctx.channel.parent_id in channels:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than adding the thread to the whitelisted channels, it makes more sense to check the parent channel instead of ctx.channel in this case. This also keeps the in channels check in one place.

Copy link
Copy Markdown
Member

@mbaruh mbaruh Mar 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fwiw I usually do a hasattr(ctx.channel, "parent") check whenever I have to do something like this, and save the extra import, but that's more a matter of style.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just wanted to avoid multiple ifs within each other, but i can do that if you want

Copy link
Copy Markdown
Member

@mbaruh mbaruh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@shtlrs shtlrs merged commit 4b4b4bf into python-discord:main Mar 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants