Clean up bot python

This commit is contained in:
chillymosh 2021-08-28 21:42:12 +01:00
parent 7869213060
commit 38d4c0ec1b

View File

@ -379,11 +379,9 @@ class BotBase(GroupMixin):
TypeError TypeError
The coroutine passed is not actually a coroutine. The coroutine passed is not actually a coroutine.
""" """
if not asyncio.iscoroutinefunction(coro): return self._raise_expected_coro(
raise TypeError('The pre-invoke hook must be a coroutine.') coro, 'The pre-invoke hook must be a coroutine.'
)
self._before_invoke = coro
return coro
def after_invoke(self, coro: CFT) -> CFT: def after_invoke(self, coro: CFT) -> CFT:
r"""A decorator that registers a coroutine as a post-invoke hook. r"""A decorator that registers a coroutine as a post-invoke hook.
@ -412,10 +410,15 @@ class BotBase(GroupMixin):
TypeError TypeError
The coroutine passed is not actually a coroutine. The coroutine passed is not actually a coroutine.
""" """
if not asyncio.iscoroutinefunction(coro): return self._raise_expected_coro(
raise TypeError('The post-invoke hook must be a coroutine.') coro, 'The post-invoke hook must be a coroutine.'
)
def _raise_expected_coro(self, coro, arg1):
if not asyncio.iscoroutinefunction(coro):
raise TypeError(arg1)
self._after_invoke = coro
return coro return coro
# listener registration # listener registration
@ -626,10 +629,12 @@ class BotBase(GroupMixin):
# remove all the listeners from the module # remove all the listeners from the module
for event_list in self.extra_events.copy().values(): for event_list in self.extra_events.copy().values():
remove = [] remove = [
for index, event in enumerate(event_list): index
if event.__module__ is not None and _is_submodule(name, event.__module__): for index, event in enumerate(event_list)
remove.append(index) if event.__module__ is not None
and _is_submodule(name, event.__module__)
]
for index in reversed(remove): for index in reversed(remove):
del event_list[index] del event_list[index]