[commands] Add call_once keyword-only parameter for Bot.remove_check
Technically a breaking change. This is to be a parallel with the Bot.add_check interface.
This commit is contained in:
parent
3727ea9811
commit
e12db3a25d
@ -281,7 +281,7 @@ class BotBase(GroupMixin):
|
|||||||
else:
|
else:
|
||||||
self._checks.append(func)
|
self._checks.append(func)
|
||||||
|
|
||||||
def remove_check(self, func):
|
def remove_check(self, func, *, call_once=False):
|
||||||
"""Removes a global check from the bot.
|
"""Removes a global check from the bot.
|
||||||
|
|
||||||
This function is idempotent and will not raise an exception
|
This function is idempotent and will not raise an exception
|
||||||
@ -291,15 +291,16 @@ class BotBase(GroupMixin):
|
|||||||
-----------
|
-----------
|
||||||
func
|
func
|
||||||
The function to remove from the global checks.
|
The function to remove from the global checks.
|
||||||
|
call_once: bool
|
||||||
|
If the function was added with ``call_once=True`` in
|
||||||
|
the :meth:`.Bot.add_check` call or using :meth:`.check_once`.
|
||||||
"""
|
"""
|
||||||
|
l = self._check_once if call_once else self._checks
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self._checks.remove(func)
|
l.remove(func)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
try:
|
pass
|
||||||
self._check_once.remove(func)
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def check_once(self, func):
|
def check_once(self, func):
|
||||||
r"""A decorator that adds a "call once" global check to the bot.
|
r"""A decorator that adds a "call once" global check to the bot.
|
||||||
@ -649,7 +650,7 @@ class BotBase(GroupMixin):
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
self.remove_check(check)
|
self.remove_check(check, call_once=True)
|
||||||
|
|
||||||
unloader_name = '_{0.__class__.__name__}__unload'.format(cog)
|
unloader_name = '_{0.__class__.__name__}__unload'.format(cog)
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user