Fix issues with the black/whitelist cache #3643

Merged
TrustyJAID merged 4 commits from black-white-list-fixes into V3/develop 2020-03-21 18:14:50 +01:00
TrustyJAID commented 2020-03-08 18:28:48 +01:00 (Migrated from github.com)

Type

  • Bugfix
  • Enhancement
  • New feature

Description of the changes

Fixes some issues with the black/whitelist cache and fixes #3642

### Type - [x] Bugfix - [ ] Enhancement - [ ] New feature ### Description of the changes Fixes some issues with the black/whitelist cache and fixes #3642
Twentysix26 (Migrated from github.com) reviewed 2020-03-08 18:28:48 +01:00
Jackenmen (Migrated from github.com) requested changes 2020-03-12 19:06:10 +01:00
Jackenmen (Migrated from github.com) left a comment

Changes that should be made which GitHub didn't let me put comment on:

  • line 238
    Suggested change:
    self._cached_whitelist[gid] = []

  • line 204
    Suggested change:
    ret = await self._config.guild_from_id(gid).whitelist()

Changes that should be made which GitHub didn't let me put comment on: - [line 238](https://github.com/Cog-Creators/Red-DiscordBot/pull/3643/files#diff-2201ff62582a7905f645d5fbae75cd68R238) Suggested change: `self._cached_whitelist[gid] = []` - [line 204](https://github.com/Cog-Creators/Red-DiscordBot/pull/3643/files#diff-2201ff62582a7905f645d5fbae75cd68R204) Suggested change: `ret = await self._config.guild_from_id(gid).whitelist()`
@ -146,2 +146,2 @@
if not isinstance(role_or_user, list) and not all(
isinstance(r_or_u, str) for r_or_u in role_or_user
if not isinstance(role_or_user, list) or not all(
isinstance(r_or_u, int) for r_or_u in role_or_user
Jackenmen (Migrated from github.com) commented 2020-03-12 18:49:19 +01:00

This if should look like this unless I misunderstood its intent:

if not (
    isinstance(role_or_user, list) and all(
        isinstance(r_or_u, int) for r_or_u in role_or_user
    )
):
This `if` should look like this unless I misunderstood its intent: ```py if not ( isinstance(role_or_user, list) and all( isinstance(r_or_u, int) for r_or_u in role_or_user ) ): ```
Jackenmen (Migrated from github.com) commented 2020-03-12 19:02:34 +01:00

This if may result in adding empty list to the cache when in fact there is something in current whitelist which just wasn't cached just yet.

This `if` may result in adding empty list to the cache when in fact there is something in current whitelist which just wasn't cached just yet.
@ -171,19 +176,24 @@ class WhitelistBlacklistManager:
async def remove_from_whitelist(self, guild: Optional[discord.Guild], role_or_user: List[int]):
gid: Optional[int] = guild.id if guild else None
Jackenmen (Migrated from github.com) commented 2020-03-12 18:56:08 +01:00

This if should look like this unless I misunderstood its intent:

if not (
    isinstance(role_or_user, list) and all(
        isinstance(r_or_u, int) for r_or_u in role_or_user
    )
):
This `if` should look like this unless I misunderstood its intent: ```py if not ( isinstance(role_or_user, list) and all( isinstance(r_or_u, int) for r_or_u in role_or_user ) ): ```
Jackenmen (Migrated from github.com) commented 2020-03-12 19:03:03 +01:00

This if may result in adding empty list to the cache when in fact there is something in current whitelist which just wasn't cached just yet.

This `if` may result in adding empty list to the cache when in fact there is something in current whitelist which just wasn't cached just yet.
Jackenmen (Migrated from github.com) commented 2020-03-12 18:56:59 +01:00

This if should look like this unless I misunderstood its intent:

if not (
    isinstance(role_or_user, list) and all(
        isinstance(r_or_u, int) for r_or_u in role_or_user
    )
):
This `if` should look like this unless I misunderstood its intent: ```py if not ( isinstance(role_or_user, list) and all( isinstance(r_or_u, int) for r_or_u in role_or_user ) ): ```
Jackenmen (Migrated from github.com) commented 2020-03-12 19:01:56 +01:00

This if may result in adding empty list to the cache when in fact there is something in current blacklist which just wasn't cached just yet.

This `if` may result in adding empty list to the cache when in fact there is something in current blacklist which just wasn't cached just yet.
@ -232,3 +246,3 @@
self._cached_whitelist[gid]
self._cached_blacklist[gid] = []
if gid is None:
await self._config.blacklist.clear()
Jackenmen (Migrated from github.com) commented 2020-03-12 18:57:04 +01:00

This if should look like this unless I misunderstood its intent:

if not (
    isinstance(role_or_user, list) and all(
        isinstance(r_or_u, int) for r_or_u in role_or_user
    )
):
This `if` should look like this unless I misunderstood its intent: ```py if not ( isinstance(role_or_user, list) and all( isinstance(r_or_u, int) for r_or_u in role_or_user ) ): ```
Jackenmen (Migrated from github.com) commented 2020-03-12 19:01:48 +01:00

This if may result in adding empty list to the cache when in fact there is something in current blacklist which just wasn't cached just yet.

This `if` may result in adding empty list to the cache when in fact there is something in current blacklist which just wasn't cached just yet.
Jackenmen (Migrated from github.com) requested changes 2020-03-13 10:32:26 +01:00
@ -143,26 +143,31 @@ class WhitelistBlacklistManager:
async def add_to_whitelist(self, guild: Optional[discord.Guild], role_or_user: List[int]):
Jackenmen (Migrated from github.com) commented 2020-03-13 08:25:44 +01:00

This if is still not correct - it only triggers if role_or_user is not a list and all items in the list (and first part just checked that it's not a list) are integers

It should either be:

if not (
    isinstance(role_or_user, list) and all(
        isinstance(r_or_u, int) for r_or_u in role_or_user
    )
):

or if you think it's clearer when using or then:

if not isinstance(role_or_user, list) or not all(
        isinstance(r_or_u, int) for r_or_u in role_or_user
):

Same thing applies to other 3 ifs that I previously commented on.

This `if` is still not correct - it only triggers if `role_or_user` is not a list **and** all items in the list (and first part just checked that it's not a list) are integers It should either be: ```py if not ( isinstance(role_or_user, list) and all( isinstance(r_or_u, int) for r_or_u in role_or_user ) ): ``` or if you think it's clearer when using `or` then: ```py if not isinstance(role_or_user, list) or not all( isinstance(r_or_u, int) for r_or_u in role_or_user ): ``` Same thing applies to other 3 `if`s that I previously commented on.
@ -171,19 +176,24 @@ class WhitelistBlacklistManager:
async def remove_from_whitelist(self, guild: Optional[discord.Guild], role_or_user: List[int]):
gid: Optional[int] = guild.id if guild else None
Jackenmen (Migrated from github.com) commented 2020-03-13 10:30:05 +01:00

This hasn't been resolved in this function.

This hasn't been resolved in this function.
Jackenmen (Migrated from github.com) commented 2020-03-13 08:18:09 +01:00

I missed this on first review:

        self._cached_blacklist[gid] = []
I missed this on first review: ```suggestion self._cached_blacklist[gid] = [] ```
@ -232,3 +246,3 @@
self._cached_whitelist[gid]
self._cached_blacklist[gid] = []
if gid is None:
await self._config.blacklist.clear()
Jackenmen (Migrated from github.com) commented 2020-03-13 10:29:58 +01:00

This hasn't been resolved in this function.

This hasn't been resolved in this function.
@ -233,3 +246,4 @@
self._cached_blacklist[gid] = []
if gid is None:
await self._config.blacklist.clear()
else:
Jackenmen (Migrated from github.com) commented 2020-03-13 10:31:43 +01:00

I missed this on first review:

                if obj_id in self._cached_blacklist[gid]:
I missed this on first review: ```suggestion if obj_id in self._cached_blacklist[gid]: ```
Jackenmen (Migrated from github.com) approved these changes 2020-03-21 18:14:27 +01:00
Jackenmen (Migrated from github.com) left a comment

Looks good to me, thanks!

Looks good to me, thanks!
Sign in to join this conversation.
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Mrcoolgamer11/Red-DiscordBot!3643
No description provided.