|
24 | 24 | from asyncio.coroutines import iscoroutinefunction |
25 | 25 | from inspect import Parameter, isawaitable, ismethod |
26 | 26 | from types import MethodType |
27 | | -from typing import (Coroutine, Generic, TYPE_CHECKING, Any, Callable, Mapping, Optional, Tuple, |
| 27 | +from typing import (ClassVar, Coroutine, Generic, TYPE_CHECKING, Any, Callable, Mapping, Optional, Tuple, |
28 | 28 | Type, TypeVar, Union) |
29 | 29 |
|
30 | 30 | import discord |
@@ -133,10 +133,14 @@ async def on_error(self, ctx, error): |
133 | 133 |
|
134 | 134 | """ |
135 | 135 | cogcmd: Optional[CCmd] |
| 136 | + use_main: ClassVar[bool] = False |
136 | 137 |
|
137 | 138 | def __init__(self, func: Optional[AsyncCallable] = None, **kwargs) -> None: |
138 | | - if func is None: |
| 139 | + if func is None or self.use_main: |
139 | 140 | func = self.main |
| 141 | + self.__class__.use_main = True |
| 142 | + if Command.main.__doc__: |
| 143 | + del Command.main.__doc__ |
140 | 144 | if hasattr(func, "__doc_only__"): |
141 | 145 | raise ValueError("main method must be overridded for subclass of disctools.commands.Command if func argument is None") |
142 | 146 |
|
@@ -165,17 +169,13 @@ async def __call__(self, *args, **kwargs) -> Any: |
165 | 169 | return await self.callback(*args, **kwargs) |
166 | 170 |
|
167 | 171 | def __init_subclass__(cls, **kwargs) -> None: |
| 172 | + # I have kept this here so that, if any code divers |
| 173 | + # Want to make a command without a docstring |
| 174 | + # for some reason, besides it gives me peace of mind |
| 175 | + # to know that docstrings wont be messed with at doctime |
168 | 176 | if not kwargs.get("_root", False): |
169 | | - strip_doc = {"pre_invoke", "main", "post_invoke", "on_error"} |
170 | | - for i in strip_doc: |
171 | | - i_func = getattr(cls, i, None) |
172 | | - if i_func: |
173 | | - if hasattr(i_func, '__doc_only__'): |
174 | | - try: |
175 | | - del i_func.__doc__ |
176 | | - except AttributeError: |
177 | | - # We should never reach here |
178 | | - pass |
| 177 | + # Assign class's doc to main mehod |
| 178 | + # if main method doesn't have the doc |
179 | 179 | main_m = getattr(cls, "main", None) |
180 | 180 | if getattr(main_m, "__doc__", None) is None: |
181 | 181 | setattr(main_m, '__doc__', getattr(cls, '__doc__', None)) |
@@ -352,7 +352,7 @@ async def call_before_hooks(self, ctx: Context) -> None: |
352 | 352 | _arg: Union[Tuple[Optional[Cog], Context], Tuple[Context]] = (cog, ctx) |
353 | 353 | else: |
354 | 354 | _arg = (ctx,) |
355 | | - self.call_if_overridden(self._before_invoke, *_arg) |
| 355 | + await self.call_if_overridden(self._before_invoke, *_arg) |
356 | 356 |
|
357 | 357 | async def call_after_hooks(self, ctx: Context) -> None: |
358 | 358 | cog = self.cog |
|
0 commit comments