Skip to content

fix: correctly serialize slash cmd with same names from different scope #1733

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions interactions/models/internal/application_commands.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
from collections import defaultdict
import inspect
import re
import typing
Expand Down Expand Up @@ -1466,9 +1467,9 @@ def application_commands_to_dict( # noqa: C901
`Client.interactions` should be the variable passed to this

"""
cmd_bases = {} # {cmd_base: [commands]}
cmd_bases: defaultdict[str, list[InteractionCommand]] = defaultdict(list) # {cmd_base: [commands]}
"""A store of commands organised by their base command"""
output = {}
output: defaultdict["Snowflake_Type", list[dict]] = defaultdict(list)
"""The output dictionary"""

def squash_subcommand(subcommands: List) -> Dict:
Expand Down Expand Up @@ -1514,9 +1515,6 @@ def squash_subcommand(subcommands: List) -> Dict:
for _scope, cmds in commands.items():
for cmd in cmds.values():
cmd_name = str(cmd.name)
if cmd_name not in cmd_bases:
cmd_bases[cmd_name] = [cmd]
continue
if cmd not in cmd_bases[cmd_name]:
cmd_bases[cmd_name].append(cmd)

Expand Down Expand Up @@ -1556,15 +1554,14 @@ def squash_subcommand(subcommands: List) -> Dict:
cmd.nsfw = nsfw
# end validation of attributes
cmd_data = squash_subcommand(cmd_list)

for s in scopes:
output[s].append(cmd_data)
else:
scopes = cmd_list[0].scopes
cmd_data = cmd_list[0].to_dict()
for s in scopes:
if s not in output:
output[s] = [cmd_data]
continue
output[s].append(cmd_data)
return output
for cmd in cmd_list:
for s in cmd.scopes:
output[s].append(cmd.to_dict())
return dict(output)


def _compare_commands(local_cmd: dict, remote_cmd: dict) -> bool:
Expand Down
Loading