Skip to content

Commit c642596

Browse files
committed
revert: "fix: workaround for interactions-py/interactions.py#1680"
This reverts commit 5929374.
1 parent 4d6c83e commit c642596

File tree

1 file changed

+4
-71
lines changed

1 file changed

+4
-71
lines changed

common/utils.py

Lines changed: 4 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import asyncio
1818
import collections
1919
import datetime
20-
import inspect
2120
import logging
2221
import os
2322
import re
@@ -516,75 +515,9 @@ async def _global_checks(ctx: RealmContext) -> bool:
516515

517516

518517
class Extension(ipy.Extension):
519-
# replica of https://github.com/interactions-py/interactions.py/pull/1680
520518
def __new__(
521-
cls, bot: ipy.Client, *_: typing.Any, **kwargs: typing.Any
519+
cls, bot: ipy.Client, *args: typing.Any, **kwargs: typing.Any
522520
) -> ipy.Extension:
523-
instance = object.__new__(cls)
524-
instance.bot = bot
525-
instance.client = bot
526-
527-
instance.name = cls.__name__
528-
529-
if instance.name in bot.ext:
530-
raise ValueError(
531-
f"An extension with the name {instance.name} is already loaded!"
532-
)
533-
534-
instance.extension_name = inspect.getmodule(instance).__name__
535-
instance.extension_checks = []
536-
instance.extension_prerun = []
537-
instance.extension_postrun = []
538-
instance.extension_error = None
539-
instance.interaction_tree = {}
540-
instance.auto_defer = ipy.MISSING
541-
542-
instance.description = kwargs.get("Description") or (
543-
inspect.cleandoc(cls.__doc__) if cls.__doc__ else None
544-
)
545-
546-
# load commands from class
547-
instance._commands = []
548-
instance._listeners = []
549-
550-
callables: list[tuple[str, typing.Callable]] = inspect.getmembers(
551-
instance, predicate=lambda x: isinstance(x, ipy.CallbackObject | ipy.Task)
552-
)
553-
554-
for _name, val in callables:
555-
if isinstance(val, ipy.BaseCommand):
556-
val.extension = instance
557-
val = ipy.utils.wrap_partial(val, instance)
558-
bot.add_command(val)
559-
instance._commands.append(val)
560-
561-
elif isinstance(val, ipy.Task):
562-
ipy.utils.wrap_partial(val, instance)
563-
564-
elif isinstance(val, ipy.Listener):
565-
val.extension = instance
566-
val = val.copy_with_binding(instance)
567-
bot.add_listener(val) # type: ignore
568-
instance._listeners.append(val)
569-
elif isinstance(val, ipy.GlobalAutoComplete):
570-
val.extension = instance
571-
val = val.copy_with_binding(instance)
572-
bot.add_global_autocomplete(val)
573-
bot.dispatch(
574-
ipy.events.ExtensionCommandParse(extension=instance, callables=callables)
575-
)
576-
577-
instance.bot.ext[instance.name] = instance
578-
579-
if hasattr(instance, "async_start"):
580-
if inspect.iscoroutinefunction(instance.async_start):
581-
bot.async_startup_tasks.append((instance.async_start, (), {}))
582-
else:
583-
raise TypeError(
584-
"async_start is a reserved method and must be a coroutine"
585-
)
586-
587-
bot.dispatch(ipy.events.ExtensionLoad(extension=instance))
588-
589-
instance.add_ext_check(_global_checks) # type: ignore the only real new line
590-
return instance
521+
new_cls = super().__new__(cls, bot, *args, **kwargs)
522+
new_cls.add_ext_check(_global_checks) # type: ignore
523+
return new_cls

0 commit comments

Comments
 (0)