Skip to content

Commit 5de15f2

Browse files
committed
fix: rewrite warning logic into cmd init
1 parent 130b432 commit 5de15f2

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

discord/ext/bridge/core.py

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,28 @@ class BridgeExtCommand(Command):
9696
def __init__(self, func, **kwargs):
9797
super().__init__(func, **kwargs)
9898

99+
# TODO: v2.7: Remove backwards support for Option in bridge commands.
100+
for name, option in self.params.items():
101+
if isinstance(option.annotation, Option) and not isinstance(
102+
option.annotation, BridgeOption
103+
):
104+
# Warn not to do this
105+
warn_deprecated(
106+
"Using Option for bridge commands",
107+
"BridgeOption",
108+
"2.5",
109+
"2.7",
110+
reference="https://github.com/Pycord-Development/pycord/pull/2417",
111+
stacklevel=6,
112+
)
113+
# Override the convert method of the parameter's annotated Option.
114+
# We can use the convert method from BridgeOption, and bind "self"
115+
# using a manual invocation of the descriptor protocol.
116+
# Definitely not a good approach, but gets the job done until removal.
117+
self.params[name].annotation.convert = BridgeOption.convert.__get__(
118+
self.params[name].annotation
119+
)
120+
99121
async def dispatch_error(self, ctx: BridgeExtContext, error: Exception) -> None:
100122
await super().dispatch_error(ctx, error)
101123
ctx.bot.dispatch("bridge_command_error", ctx, error)
@@ -653,27 +675,3 @@ def decorator(func):
653675
return func
654676

655677
return decorator
656-
657-
658-
# TODO: Fix this, it doesn't work if discord.Option is imported before discord.ext.bridge
659-
660-
661-
# TODO: 2.7: Remove this
662-
class BridgeOptionDeprecated(BridgeOption):
663-
@staticmethod
664-
def _warn():
665-
warn_deprecated(
666-
"Option",
667-
"BridgeOption",
668-
"2.5",
669-
"2.7",
670-
reference="https://github.com/Pycord-Development/pycord/pull/2417",
671-
)
672-
673-
def __init__(self, *args, **kwargs):
674-
self._warn()
675-
super().__init__(*args, **kwargs)
676-
677-
678-
discord.commands.options.Option = BridgeOptionDeprecated
679-
discord.Option = BridgeOptionDeprecated

0 commit comments

Comments
 (0)