decorators Module

decorators Module

decorators.debugonly(f_or_text=None, **kwargs)[source]

A decorator to prevent commands being run outside of debug mode.

If the function is awaited when skybeard is not in debug mode, it sends a message to the user. If skybeard is run in debug mode, then it executes the body of the function.

If passed a string as the first argument, it sends that message instead of the default message when not in debug mode.

e.g.

@debugonly("Skybeard is not in debug mode.")
async def foo(self, msg):
    # This message will only be sent if skybeard is run in debug mode
    await self.sender.sendMessage("You are in debug mode!")
decorators.onerror(f_or_text=None, **kwargs)[source]

A decorator for sending a message to the user on an exception.

If no arguments are used (i.e. the function is passed directly to the decorator), beard.__onerror__(exception) is called if the decorated function excepts.

If a string is passed as the first argument, then the decorated function sends this message instead of calling the beard.__onerror__ function. kwargs are passed to beard.sender.sendMessage and beard.__onerror__(exception) is called.

If only kwargs are passed, then the decorated function attempts beard.sender.sendMessage(**kwargs) and then calls beard.__onerror__(exception).