Skip to content

Commit

Permalink
fix: correctly serialize slash cmd with same names from different sco…
Browse files Browse the repository at this point in the history
…pe (#1733)
  • Loading branch information
AstreaTSS authored Aug 24, 2024
1 parent 7c9de39 commit d5dfe8e
Showing 1 changed file with 10 additions and 13 deletions.
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 @@ -1468,9 +1469,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 @@ -1516,9 +1517,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 @@ -1558,15 +1556,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

0 comments on commit d5dfe8e

Please sign in to comment.