1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00

More commands done

This commit is contained in:
Steffo 2019-11-29 15:55:52 +01:00
parent 491301b681
commit f1803f2ffd
5 changed files with 16 additions and 6 deletions

View file

@ -5,6 +5,6 @@ class ExceptionEvent(Event):
name = "exception" name = "exception"
def run(self, **kwargs): def run(self, **kwargs):
if not self.interface.cfg["exc_debug"]: if not self.interface.config["exc_debug"]:
raise UserError(f"{self.interface.prefix}{self.name} is not enabled.") raise UserError(f"{self.interface.prefix}{self.name} is not enabled.")
raise Exception(f"{self.name} event was called") raise Exception(f"{self.name} event was called")

View file

@ -27,6 +27,11 @@ class Command:
def __init__(self, interface: CommandInterface): def __init__(self, interface: CommandInterface):
self.interface = interface self.interface = interface
@property
def serf(self):
"""A shortcut for :attr:`.interface.serf`."""
return self.interface.serf
@property @property
def alchemy(self): def alchemy(self):
"""A shortcut for :attr:`.interface.alchemy`.""" """A shortcut for :attr:`.interface.alchemy`."""
@ -37,5 +42,10 @@ class Command:
"""A shortcut for :attr:`.interface.loop`.""" """A shortcut for :attr:`.interface.loop`."""
return self.interface.loop return self.interface.loop
@property
def config(self):
"""A shortcut for :attr:`.interface.config`."""
return self.interface.config
async def run(self, args: CommandArgs, data: CommandData) -> None: async def run(self, args: CommandArgs, data: CommandData) -> None:
raise NotImplementedError() raise NotImplementedError()

View file

@ -48,8 +48,8 @@ class CommandInterface:
# TODO # TODO
raise Exception("TODO") raise Exception("TODO")
def __init__(self, cfg: Dict[str, Any]): def __init__(self, config: Dict[str, Any]):
self.cfg: Dict[str, Any] = cfg self.config: Dict[str, Any] = config
"""The config section for the pack of the command.""" """The config section for the pack of the command."""
# Will be bound after the command/event has been created # Will be bound after the command/event has been created

View file

@ -225,7 +225,7 @@ class Constellation:
def register_events(self, events: List[Type[rc.Event]], pack_cfg: Dict[str, Any]): def register_events(self, events: List[Type[rc.Event]], pack_cfg: Dict[str, Any]):
for SelectedEvent in events: for SelectedEvent in events:
# Create a new interface # Create a new interface
interface = self.Interface(cfg=pack_cfg) interface = self.Interface(config=pack_cfg)
# Initialize the event # Initialize the event
try: try:
event = SelectedEvent(interface) event = SelectedEvent(interface)

View file

@ -203,7 +203,7 @@ class Serf:
# Instantiate the Commands # Instantiate the Commands
for SelectedCommand in commands: for SelectedCommand in commands:
# Create a new interface # Create a new interface
interface = self.Interface(cfg=pack_cfg) interface = self.Interface(config=pack_cfg)
# Try to instantiate the command # Try to instantiate the command
try: try:
command = SelectedCommand(interface) command = SelectedCommand(interface)
@ -241,7 +241,7 @@ class Serf:
def register_events(self, events: List[Type[Event]], pack_cfg: Dict[str, Any]): def register_events(self, events: List[Type[Event]], pack_cfg: Dict[str, Any]):
for SelectedEvent in events: for SelectedEvent in events:
# Create a new interface # Create a new interface
interface = self.Interface(cfg=pack_cfg) interface = self.Interface(config=pack_cfg)
# Initialize the event # Initialize the event
try: try:
event = SelectedEvent(interface) event = SelectedEvent(interface)