pylav.extension.red.utils package#

Submodules#

pylav.extension.red.utils.decorators module#

pylav.extension.red.utils.decorators.always_hidden(slash=False)[source]#
pylav.extension.red.utils.decorators.can_run_command_in_channel(slash=False)[source]#
pylav.extension.red.utils.decorators.invoker_is_dj(slash=False)[source]#
async pylav.extension.red.utils.decorators.is_dj_logic(context, bot=None)[source]#
pylav.extension.red.utils.decorators.requires_player(slash=False)[source]#

pylav.extension.red.utils.required_methods module#

pylav.extension.red.utils.required_methods.class_factory(bot, cls, cogargs, cogkwargs)[source]#

Creates a new class which inherits from the given class and overrides the following methods: - cog_check - cog_unload - cog_before_invoke - initialize - cog_command_error

async pylav.extension.red.utils.required_methods.cog_before_invoke(self, context)[source]#
async pylav.extension.red.utils.required_methods.cog_check(self, context)[source]#
async pylav.extension.red.utils.required_methods.cog_command_error(self, context, error)[source]#
async pylav.extension.red.utils.required_methods.cog_unload(self)[source]#
async pylav.extension.red.utils.required_methods.initialize(self, *args, **kwargs)[source]#
async pylav.extension.red.utils.required_methods.pylav_auto_setup(bot, cog_cls, cogargs=None, cogkwargs=None, initargs=None, initkwargs=None)[source]#

Injects all the methods and attributes to respect PyLav Settings and keep the user experience consistent.

Adds .bot attribute to the cog instance. Adds .pylav attribute to the cog instance and starts up PyLav Overwrites cog_unload method to unregister the cog from Lavalink, calling the original cog_unload method once the PyLav unregister code is run. Overwrites cog_before_invoke To force commands to wait for PyLav to be ready Overwrites cog_check method to check if the cog is allowed to run in the current context. If called within a Guild then we check if we can run as per the PyLav Command channel lock, if this check passes then the original cog_check method is called. Overwrites cog_command_error method to handle PyLav errors raised by the cog, if the cog defines their own cog_command_error method, this will still be called after the built-in PyLav error handling if the error raised was unhandled. Overwrites initialize method to handle PyLav startup, calling the original initialize method once the PyLav initialization code is run, if such method exists. code is run.

Parameters:
  • bot (DISCORD_BOT_TYPE) – The bot instance to load the cog instance to.

  • cog_cls (type[DISCORD_COG_TYPE]) – The cog class load.

  • cogargs (tuple[object]) – The arguments to pass to the cog class.

  • cogkwargs (dict[str, object]) – The keyword arguments to pass to the cog class.

  • initargs (tuple[object]) – The arguments to pass to the initialize method.

  • initkwargs (dict[str, object]) – The keyword arguments to pass to the initialize method.

Returns:

The cog instance loaded to the bot.

Return type:

DISCORD_COG_TYPE

Example

>>> from pylav.extension.red.utils.required_methods import pylav_auto_setup
>>> from discord.ext.commands import Cog
>>> class MyCogClass(Cog):
...     def __init__(self, bot: DISCORD_BOT_TYPE, special_arg: object):
...         self.bot = bot
...         self.special_arg = special_arg
>>> async def setup(bot: DISCORD_BOT_TYPE) -> None:
...     await pylav_auto_setup(bot, MyCogClass, cogargs=(), cogkwargs=dict(special_arg=42), initargs=(),
initkwargs=dict())

pylav.extension.red.utils.validators module#

pylav.extension.red.utils.validators.valid_query_attachment(attachment_name)[source]#

Module contents#

class pylav.extension.red.utils.CompositeMetaClass(*args, **kwargs)[source]#

Bases: CogMeta, ABCMeta

This allows the metaclass used for proper type detection to coexist with discord.py’s metaclass

class pylav.extension.red.utils.Mutator(obj)[source]#

Bases: object

pylav.extension.red.utils.recursive_merge(d1, d2)[source]#

Update two dicts of dicts recursively, if either mapping has leaves that are non-dicts, the second’s leaf overwrites the first’s.

pylav.extension.red.utils.rgetattr(obj, attr, *args)[source]#
pylav.extension.red.utils.rsetattr(obj, attr, val)[source]#