Skip to content
This repository was archived by the owner on Aug 29, 2021. It is now read-only.

Commit 2a05777

Browse files
committed
[commands] Fix bug which prevented prpoer use with cogs
1 parent 0a53287 commit 2a05777

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

disctools/commands.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from asyncio.coroutines import iscoroutinefunction
2525
from inspect import Parameter, isawaitable, ismethod
2626
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,
2828
Type, TypeVar, Union)
2929

3030
import discord
@@ -133,10 +133,14 @@ async def on_error(self, ctx, error):
133133
134134
"""
135135
cogcmd: Optional[CCmd]
136+
use_main: ClassVar[bool] = False
136137

137138
def __init__(self, func: Optional[AsyncCallable] = None, **kwargs) -> None:
138-
if func is None:
139+
if func is None or self.use_main:
139140
func = self.main
141+
self.__class__.use_main = True
142+
if Command.main.__doc__:
143+
del Command.main.__doc__
140144
if hasattr(func, "__doc_only__"):
141145
raise ValueError("main method must be overridded for subclass of disctools.commands.Command if func argument is None")
142146

@@ -165,17 +169,13 @@ async def __call__(self, *args, **kwargs) -> Any:
165169
return await self.callback(*args, **kwargs)
166170

167171
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
168176
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
179179
main_m = getattr(cls, "main", None)
180180
if getattr(main_m, "__doc__", None) is None:
181181
setattr(main_m, '__doc__', getattr(cls, '__doc__', None))
@@ -352,7 +352,7 @@ async def call_before_hooks(self, ctx: Context) -> None:
352352
_arg: Union[Tuple[Optional[Cog], Context], Tuple[Context]] = (cog, ctx)
353353
else:
354354
_arg = (ctx,)
355-
self.call_if_overridden(self._before_invoke, *_arg)
355+
await self.call_if_overridden(self._before_invoke, *_arg)
356356

357357
async def call_after_hooks(self, ctx: Context) -> None:
358358
cog = self.cog

0 commit comments

Comments
 (0)