A-0.1 - Modularer Aufbau #13
@ -1,14 +1,21 @@
|
|||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
|
|
||||||
import discord
|
|
||||||
|
|
||||||
class ModuleABC(ABC):
|
class ModuleABC(ABC):
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._priorities = {}
|
self._priorities = {}
|
||||||
|
self._success = True
|
||||||
|
|
||||||
def get_priority(self, t: type) -> int:
|
def get_priority(self, t: type) -> int:
|
||||||
if t not in self._priorities:
|
if t not in self._priorities:
|
||||||
raise Exception(f'Priority for {t} not found!')
|
raise Exception(f'Priority for {t} not found!')
|
||||||
return self._priorities[t]
|
return self._priorities[t]
|
||||||
|
|
||||||
|
def stop_propagation(self):
|
||||||
|
self._success = False
|
||||||
|
|
||||||
|
@property
|
||||||
|
def success(self) -> bool:
|
||||||
|
return self._success
|
||||||
|
@ -91,6 +91,9 @@ class ModuleService(ModuleServiceABC, commands.Cog, metaclass=_MetaCogABC):
|
|||||||
for module in modules:
|
for module in modules:
|
||||||
func = getattr(module, func_name)
|
func = getattr(module, func_name)
|
||||||
await func(*args)
|
await func(*args)
|
||||||
|
if not module.success:
|
||||||
|
self._logger.debug(__name__, f'Stopped progation for {event} from {type(module)}')
|
||||||
|
break
|
||||||
|
|
||||||
self._logger.debug(__name__, f'Stopped {event} modules')
|
self._logger.debug(__name__, f'Stopped {event} modules')
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user