[Permissions] Ordering fix (#3452)

This commit is contained in:
Michael H 2020-01-26 19:00:08 -05:00 committed by Kowlin
parent a8450580e8
commit 3d4f9500e9

View File

@ -9,6 +9,7 @@ checks like bot permissions checks.
import asyncio import asyncio
import enum import enum
import inspect import inspect
from collections import ChainMap
from typing import ( from typing import (
Union, Union,
Optional, Optional,
@ -21,6 +22,7 @@ from typing import (
TypeVar, TypeVar,
Tuple, Tuple,
ClassVar, ClassVar,
Mapping,
) )
import discord import discord
@ -367,6 +369,8 @@ class Requires:
guild_id : int guild_id : int
The ID of the guild for the rule's scope. Set to The ID of the guild for the rule's scope. Set to
`Requires.GLOBAL` for a global rule. `Requires.GLOBAL` for a global rule.
If a global rule is set for a model,
it will be prefered over the guild rule.
Returns Returns
------- -------
@ -377,8 +381,9 @@ class Requires:
""" """
if not isinstance(model, (str, int)): if not isinstance(model, (str, int)):
model = model.id model = model.id
rules: Mapping[Union[int, str], PermState]
if guild_id: if guild_id:
rules = self._guild_rules.get(guild_id, _RulesDict()) rules = ChainMap(self._global_rules, self._guild_rules.get(guild_id, _RulesDict()))
else: else:
rules = self._global_rules rules = self._global_rules
return rules.get(model, PermState.NORMAL) return rules.get(model, PermState.NORMAL)