|
1 | 1 | import asyncio
|
| 2 | +from collections import defaultdict |
2 | 3 | import inspect
|
3 | 4 | import re
|
4 | 5 | import typing
|
@@ -1468,9 +1469,9 @@ def application_commands_to_dict( # noqa: C901
|
1468 | 1469 | `Client.interactions` should be the variable passed to this
|
1469 | 1470 |
|
1470 | 1471 | """
|
1471 |
| - cmd_bases = {} # {cmd_base: [commands]} |
| 1472 | + cmd_bases: defaultdict[str, list[InteractionCommand]] = defaultdict(list) # {cmd_base: [commands]} |
1472 | 1473 | """A store of commands organised by their base command"""
|
1473 |
| - output = {} |
| 1474 | + output: defaultdict["Snowflake_Type", list[dict]] = defaultdict(list) |
1474 | 1475 | """The output dictionary"""
|
1475 | 1476 |
|
1476 | 1477 | def squash_subcommand(subcommands: List) -> Dict:
|
@@ -1516,9 +1517,6 @@ def squash_subcommand(subcommands: List) -> Dict:
|
1516 | 1517 | for _scope, cmds in commands.items():
|
1517 | 1518 | for cmd in cmds.values():
|
1518 | 1519 | cmd_name = str(cmd.name)
|
1519 |
| - if cmd_name not in cmd_bases: |
1520 |
| - cmd_bases[cmd_name] = [cmd] |
1521 |
| - continue |
1522 | 1520 | if cmd not in cmd_bases[cmd_name]:
|
1523 | 1521 | cmd_bases[cmd_name].append(cmd)
|
1524 | 1522 |
|
@@ -1558,15 +1556,14 @@ def squash_subcommand(subcommands: List) -> Dict:
|
1558 | 1556 | cmd.nsfw = nsfw
|
1559 | 1557 | # end validation of attributes
|
1560 | 1558 | cmd_data = squash_subcommand(cmd_list)
|
| 1559 | + |
| 1560 | + for s in scopes: |
| 1561 | + output[s].append(cmd_data) |
1561 | 1562 | else:
|
1562 |
| - scopes = cmd_list[0].scopes |
1563 |
| - cmd_data = cmd_list[0].to_dict() |
1564 |
| - for s in scopes: |
1565 |
| - if s not in output: |
1566 |
| - output[s] = [cmd_data] |
1567 |
| - continue |
1568 |
| - output[s].append(cmd_data) |
1569 |
| - return output |
| 1563 | + for cmd in cmd_list: |
| 1564 | + for s in cmd.scopes: |
| 1565 | + output[s].append(cmd.to_dict()) |
| 1566 | + return dict(output) |
1570 | 1567 |
|
1571 | 1568 |
|
1572 | 1569 | def _compare_commands(local_cmd: dict, remote_cmd: dict) -> bool:
|
|
0 commit comments