Skip to content

Commit b86e5cf

Browse files
committed
🐛 fix DiscordSlashExtension
1 parent 1165b57 commit b86e5cf

File tree

3 files changed

+43
-43
lines changed

3 files changed

+43
-43
lines changed

src/nonebot_plugin_alconna/builtins/extensions/discord.py

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@ def _translate_args(args: Args) -> list[AnyCommandOption]:
4747
if all(isinstance(x, str) for x in arg.value.base):
4848
result.append(
4949
StringOption(
50-
name=arg.name,
51-
description=arg.notice or arg.name,
50+
name=f"{arg.name}",
51+
description=f"{arg.notice or arg.name}",
5252
required=not arg.optional,
5353
choices=[OptionChoice(name=x, value=x) for x in arg.value.base], # type: ignore # noqa: E501
5454
)
5555
)
5656
elif all(isinstance(x, int) for x in arg.value.base):
5757
result.append(
5858
IntegerOption(
59-
name=arg.name,
60-
description=arg.notice or arg.name,
59+
name=f"{arg.name}",
60+
description=f"{arg.notice or arg.name}",
6161
required=not arg.optional,
6262
choices=[
6363
OptionChoice(name=str(x), value=x) for x in arg.value.base # type: ignore # noqa: E501
@@ -67,8 +67,8 @@ def _translate_args(args: Args) -> list[AnyCommandOption]:
6767
elif all(isinstance(x, float) for x in arg.value.base):
6868
result.append(
6969
NumberOption(
70-
name=arg.name,
71-
description=arg.notice or arg.name,
70+
name=f"{arg.name}",
71+
description=f"{arg.notice or arg.name}",
7272
required=not arg.optional,
7373
choices=[
7474
OptionChoice(name=str(x), value=x) for x in arg.value.base # type: ignore # noqa: E501
@@ -78,8 +78,8 @@ def _translate_args(args: Args) -> list[AnyCommandOption]:
7878
else:
7979
result.append(
8080
StringOption(
81-
name=arg.name,
82-
description=arg.notice or arg.name,
81+
name=f"{arg.name}",
82+
description=f"{arg.notice or arg.name}",
8383
required=not arg.optional,
8484
choices=[OptionChoice(name=str(x), value=str(x)) for x in arg.value.base],
8585
)
@@ -88,88 +88,88 @@ def _translate_args(args: Args) -> list[AnyCommandOption]:
8888
if arg.value == ANY:
8989
result.append(
9090
StringOption(
91-
name=arg.name,
92-
description=arg.notice or arg.name,
91+
name=f"{arg.name}",
92+
description=f"{arg.notice or arg.name}",
9393
required=not arg.optional,
9494
)
9595
)
9696
elif arg.value == INTEGER:
9797
result.append(
9898
IntegerOption(
99-
name=arg.name,
100-
description=arg.notice or arg.name,
99+
name=f"{arg.name}",
100+
description=f"{arg.notice or arg.name}",
101101
required=not arg.optional,
102102
)
103103
)
104104
elif arg.value in (FLOAT, NUMBER):
105105
result.append(
106106
NumberOption(
107-
name=arg.name,
108-
description=arg.notice or arg.name,
107+
name=f"{arg.name}",
108+
description=f"{arg.notice or arg.name}",
109109
required=not arg.optional,
110110
)
111111
)
112112
elif arg.value.origin is str:
113113
result.append(
114114
StringOption(
115-
name=arg.name,
116-
description=arg.notice or arg.name,
115+
name=f"{arg.name}",
116+
description=f"{arg.notice or arg.name}",
117117
required=not arg.optional,
118118
)
119119
)
120120
elif arg.value.origin is bool:
121121
result.append(
122122
BooleanOption(
123-
name=arg.name,
124-
description=arg.notice or arg.name,
123+
name=f"{arg.name}",
124+
description=f"{arg.notice or arg.name}",
125125
required=not arg.optional,
126126
)
127127
)
128128
elif arg.value is Image:
129129
result.append(
130130
AttachmentOption(
131-
name=arg.name,
132-
description=arg.notice or arg.name,
131+
name=f"{arg.name}",
132+
description=f"{arg.notice or arg.name}",
133133
required=not arg.optional,
134134
)
135135
)
136136
# elif arg.value == MentionUser:
137137
# result.append(
138138
# UserOption(
139-
# name=arg.name,
140-
# description=arg.notice or arg.name,
139+
# name=f"{arg.name}",
140+
# description=f"{arg.notice or arg.name}",
141141
# required=not arg.optional,
142142
# )
143143
# )
144144
# elif arg.value == MentionChannel:
145145
# result.append(
146146
# ChannelOption(
147-
# name=arg.name,
148-
# description=arg.notice or arg.name,
147+
# name=f"{arg.name}",
148+
# description=f"{arg.notice or arg.name}",
149149
# required=not arg.optional,
150150
# )
151151
# )
152152
# elif arg.value == MentionRole:
153153
# result.append(
154154
# RoleOption(
155-
# name=arg.name,
156-
# description=arg.notice or arg.name,
155+
# name=f"{arg.name}",
156+
# description=f"{arg.notice or arg.name}",
157157
# required=not arg.optional,
158158
# )
159159
# )
160160
elif arg.value.origin is At:
161161
result.append(
162162
MentionableOption(
163-
name=arg.name,
164-
description=arg.notice or arg.name,
163+
name=f"{arg.name}",
164+
description=f"{arg.notice or arg.name}",
165165
required=not arg.optional,
166166
)
167167
)
168168
else:
169169
result.append(
170170
StringOption(
171-
name=arg.name,
172-
description=arg.notice or arg.name,
171+
name=f"{arg.name}",
172+
description=f"{arg.notice or arg.name}",
173173
required=not arg.optional,
174174
)
175175
)
@@ -179,8 +179,8 @@ def _translate_args(args: Args) -> list[AnyCommandOption]:
179179
def _translate_options(opt: Union[Option, Subcommand]) -> Union[SubCommandGroupOption, SubCommandOption]:
180180
if isinstance(opt, Option):
181181
return SubCommandOption(
182-
name=opt.name,
183-
description=opt.help_text,
182+
name=f"{opt.name}",
183+
description=f"{opt.help_text}",
184184
options=_translate_args(opt.args), # type: ignore
185185
)
186186
if not opt.args.empty and opt.options:
@@ -190,11 +190,11 @@ def _translate_options(opt: Union[Option, Subcommand]) -> Union[SubCommandGroupO
190190
)
191191
if not opt.args.empty:
192192
return SubCommandOption(
193-
name=opt.name, description=opt.help_text, options=_translate_args(opt.args) # type: ignore
193+
name=f"{opt.name}", description=f"{opt.help_text}", options=_translate_args(opt.args) # type: ignore
194194
)
195195
return SubCommandGroupOption(
196-
name=opt.name,
197-
description=opt.help_text,
196+
name=f"{opt.name}",
197+
description=f"{opt.help_text}",
198198
options=[_translate_options(sub) for sub in opt.options], # type: ignore
199199
)
200200

@@ -234,8 +234,8 @@ def translate(
234234
if not (options := _translate_args(alc.args)):
235235
options = [_translate_options(opt) for opt in allow_opt]
236236
buffer = {
237-
"name": alc.command,
238-
"description": alc.meta.description,
237+
"name": f"{alc.command}",
238+
"description": f"{alc.meta.description}",
239239
"options": options,
240240
**locals(),
241241
}

src/nonebot_plugin_alconna/rule.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,9 @@ def _checker(_event: Event):
250250

251251
assert self._waiter, "Waiter function is not set, please check the initialization of AlconnaRule."
252252
assert waiter, "Waiter plugin is not installed, please install nonebot_plugin_waiter."
253-
w = waiter(["message"], Matcher, keep_session=True, block=self.comp_config.get("block", False), rule=Rule(_checker))(self._waiter)
253+
w = waiter(
254+
["message"], Matcher, keep_session=True, block=self.comp_config.get("block", False), rule=Rule(_checker)
255+
)(self._waiter)
254256

255257
while interface.available:
256258

tests/test_dc.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@
1515

1616
@pytest.mark.asyncio()
1717
async def test_dc_ext(app: App):
18-
from nonebot_plugin_alconna import Match, on_alconna, load_from_path
19-
20-
# from nonebot_plugin_alconna.adapters.discord import DiscordSlashExtension
18+
from nonebot_plugin_alconna import Match, on_alconna
19+
from nonebot_plugin_alconna.builtins.extensions.discord import DiscordSlashExtension
2120

2221
alc = Alconna(
2322
["/"],
@@ -26,8 +25,7 @@ async def test_dc_ext(app: App):
2625
Option("remove", Args["plugin", str]["time?", int]),
2726
meta=CommandMeta(description="权限管理"),
2827
)
29-
matcher = on_alconna(alc) # , extensions=[DiscordSlashExtension()])
30-
load_from_path("@discord")
28+
matcher = on_alconna(alc, extensions=[DiscordSlashExtension()])
3129

3230
@matcher.assign("add")
3331
async def add(plugin: Match[str], priority: Match[int]):

0 commit comments

Comments
 (0)