Skip to content
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

Implements #229 #239

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
20 changes: 15 additions & 5 deletions jishaku/features/management.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@
from jishaku.types import ContextA


class SyncFlags(commands.FlagConverter, prefix="", delimiter=""):
"""
A flag converter for the sync command.
"""
targets: typing.Tuple[str, ...] = commands.flag(positional=True, default=())
clear: typing.List[int] = commands.flag(aliases=["-"], default=[])


class ManagementFeature(Feature):
"""
Feature containing the extension and bot control commands
Expand Down Expand Up @@ -200,7 +208,7 @@ async def jsk_rtt(self, ctx: ContextA):
SLASH_COMMAND_ERROR = re.compile(r"In ((?:\d+\.[a-z]+\.?)+)")

@Feature.Command(parent="jsk", name="sync")
async def jsk_sync(self, ctx: ContextA, *targets: str):
async def jsk_sync(self, ctx: ContextA, *, flags: SyncFlags):
"""
Sync global or guild application commands to Discord.
"""
Expand All @@ -211,8 +219,8 @@ async def jsk_sync(self, ctx: ContextA, *targets: str):

paginator = commands.Paginator(prefix='', suffix='')

guilds_set: typing.Set[typing.Optional[int]] = set()
for target in targets:
guilds_set: typing.Set[typing.Optional[int]] = set(flags.clear)
for target in flags.targets:
if target == '$':
guilds_set.add(None)
elif target == '*':
Expand All @@ -229,7 +237,7 @@ async def jsk_sync(self, ctx: ContextA, *targets: str):
except ValueError as error:
raise commands.BadArgument(f"{target} is not a valid guild ID") from error

if not targets:
if not (flags.targets or flags.clear):
guilds_set.add(None)

guilds: typing.List[typing.Optional[int]] = list(guilds_set)
Expand All @@ -242,7 +250,9 @@ async def jsk_sync(self, ctx: ContextA, *targets: str):
translator = getattr(self.bot.tree, 'translator', None)
needs_dpy_2_4_signature_changes = discord.version_info.major >= 2 and discord.version_info.minor >= 4

if needs_dpy_2_4_signature_changes:
if guild in flags.clear:
payload = []
elif needs_dpy_2_4_signature_changes:
if translator:
payload = [await command.get_translated_payload(self.bot.tree, translator) for command in slash_commands]
else:
Expand Down