def __init_subclass__(cls, *, game_cls, cmd=None, aliases=(), **kwargs): super().__init_subclass__(**kwargs) cls.__game_class__ = game_cls cmd_name = cmd or cls.__name__.lower() group_help = inspect.getdoc(cls._game).format(name=cls.name) group_command = commands.group( name=cmd_name, aliases=aliases, help=group_help, invoke_without_command=True )(cls._game) setattr(cls, f'{cmd_name}', group_command) gc = group_command.command for name, member in inspect.getmembers(cls): if not name.startswith('_game_'): continue name = name[6:] if name in {'invite', 'create'}: # Special treatment is needed for these two continue help = inspect.getdoc(member).format(name=cls.name, cmd=cmd_name) command = gc(name=name, help=help)(member) setattr(cls, f'{cmd_name}_{name}', command) setattr(cls, f'_{cls.__name__}__error', cls._error) # Deprecate create and invite dc = functools.partial(gc, cls=DeprecatedCommand, version='1.2') setattr(cls, f'{cmd_name}_create', dc(name='create', instead=f'{cmd_name}')(cls._game_create)) setattr(cls, f'{cmd_name}_invite', dc(name='invite', instead=f'{cmd_name} @user')(cls._game_invite))
def wrapper(f): def check(ctx): return get_module(f.__module__).cog.check_once(ctx) if "checks" in kwargs: checks = kwargs.pop("checks").copy() checks.append(check) else: checks = [check] grp = commands.group(*args, **kwargs)(f) grp.checks += checks return grp
def c_group(**kwargs): """ Decorator for groups Parameters ---------- kwargs Returns ------- Decorator that transform a function into a Group """ return commands.group(**kwargs)
def __init_subclass__(cls, *, game_cls, name=None, cmd=None, aliases=(), **kwargs): super().__init_subclass__(**kwargs) cls.name = name or cls.__name__ cls.__game_class__ = game_cls cmd_name = cmd or cls.__name__.lower() group_help = inspect.getdoc(cls._game).format(name=cls.name) # We can't use the decorator because all the check decorator does is # add the predicate to an attribute called __commands_checks__, which # gets deleted after the first command. group = commands.group(name=cmd_name, aliases=aliases, help=group_help, invoke_without_command=True) group_command = group( commands.bot_has_permissions(embed_links=True)(cls._game)) setattr(cls, f'{cmd_name}', group_command) gc = group_command.command for name, member in inspect.getmembers(cls): if not name.startswith('_game_'): continue name = name[6:] game_help = inspect.getdoc(member).format(name=cls.name, cmd=cmd_name) command = gc(name=name, help=game_help)(member) setattr(cls, f'{cmd_name}_{name}', command) setattr(cls, f'_{cls.__name__}__error', cls._error)
def group(level: int, **kwargs: Any) -> Callable: """Overwrites the default group to use RainGroup""" kwargs['perm_level'] = level return commands.group(cls=RainGroup, **kwargs)
def group(name=None, cls=Group, **attrs): cls = cls or Group if not issubclass(cls, Group): raise TypeError("Use commands.group instead.") return commands.group(name=name, cls=cls, **attrs)
def groupExtra(*args, **kwargs): return commands.group(*args, **kwargs, cls=GroupPlus)
def grp(*args, **kwargs): return commands.group(*args, **kwargs, cls=GroupExtension)
def group(*args, **kwargs): return _dpy_commands.group(*args, cls=Group, **kwargs)
def decorator(func): result = commands.group(*args, **kwargs)(func) self.add_command(result) return result
def group(*args, **kwargs): if 'case_insensitive' not in kwargs: kwargs['case_insensitive'] = True return _dpy_commands.group(*args, cls=Group, **kwargs)
def cog_unload(self): self.bot.help_command = self._original_help_command @commands.group(invoke_without_command=True) @checks.has_permissions(PermissionLevel.OWNER) @utils.trigger_typing
def group(level, *args, **kwargs): """Overwrites the default group to use RainGroup""" kwargs['perm_level'] = level return commands.group(cls=RainGroup, *args, **kwargs)
def group(*args, **kwargs): kwargs.update(cls=NyaGroup) return commands.group(*args, **kwargs)
def group(name=None, **attrs): attrs['cls'] = Group return dpy_commands.group(name=name, **attrs)
def group(*args, **kwargs): return commands.group(*args, cls=GroupWithLocale, **kwargs)
def group(**kwargs): """Links command groups""" kwargs.setdefault('cls', Group) return commands.group(**kwargs)
def decorator(func): category = kwargs.get("category") func.command_category = category result = commands.group(*args, **kwargs)(func) return result